PowerShell Version 5 New Feature: New Parameters added to the New-DscCheckSum and Test-DscConfiguration Cmdlets

I’m continuing on my series of blog articles on the new features in the preview version of PowerShell version 5. Today I’ll be discussing the existing DSC (Desired State Configuration) cmdlets in PowerShell version 4 that now have new parameters as of the May 2014 preview version of PowerShell version 5.

To begin, I’ll define a DSC configuration that’s parameterized so that it’s reusable:

configuration iSCSI {

    param (
        [Parameter(Mandatory)]
        [string[]]$ComputerName
    )

    node $ComputerName {

        WindowsFeature MultipathIO {
            Name = 'Multipath-IO'
            Ensure = 'Present'
        }

        Service iSCSIService {
            Name = 'MSiSCSI'
            StartupType = 'Automatic'
            State = 'Running'
        }

    }
}

ps5-dsc1a.jpg

Run the configuration specifying the computer names to create MOF files for:

iSCSI -ComputerName SQL01, WEB01

ps5-dsc2.jpg

In the preview version of PowerShell version 5,  the New-DscCheckSum cmdlet now has a WhatIf parameter:

New-DscCheckSum -ConfigurationPath .\iSCSI -WhatIf

ps5-dsc3.jpg

A Confirm parameter has also been added to the New-DscCheckSum cmdlet:

New-DscCheckSum -ConfigurationPath .\iSCSI -Confirm

ps5-dsc4.jpg

Verify the state of the specific features and services on the servers:

Invoke-Command -ComputerName SQL01, WEB01 {
    Get-WindowsFeature -Name Multipath-IO
} | Select-Object -Property PSComputerName, Name, Installed

Invoke-Command -ComputerName SQL01, WEB01 {
    Get-CimInstance -ClassName Win32_Service -Filter "Name = 'MSiSCSI'"
} | Select-Object -Property PSComputerName, Name, State, StartMode

ps5-dsc5.jpg

Apply the DSC configuration:

Start-DscConfiguration -ComputerName SQL01, WEB01 -Path .\iSCSI -Wait -Verbose

ps5-dsc6.jpg

Check the status of the features and services again:

Invoke-Command -ComputerName SQL01, WEB01 {
    Get-WindowsFeature -Name Multipath-IO
} | Select-Object -Property PSComputerName, Name, Installed

Invoke-Command -ComputerName SQL01, WEB01 {
    Get-CimInstance -ClassName Win32_Service -Filter "Name = 'MSiSCSI'"
} | Select-Object -Property PSComputerName, Name, State, StartMode

ps5-dsc7.jpg

Test the DSC configuration using the Test-DscConfiguration cmdlet:

Test-DscConfiguration -CimSession SQL01, WEB01

ps5-dsc8.jpg

Note: In the previous example, the CimSession parameter is used even though there isn’t a CimSession to SQL01 and WEB01. The computer names can simply be specified in this scenario. This isn’t a new feature as this works in PowerShell version 4 as well, but it is something to be aware of so that you don’t necessarily have to create a CimSession first.

A Detailed parameter has been added to the Test-DscConfiguration cmdlet in the PowerShell version 5 preview:

Test-DscConfiguration -CimSession WEB01 -Detailed

ps5-dsc9.jpg

Test-DscConfiguration -CimSession WEB01 -Detailed | Select-Object -ExpandProperty ResourceID

ps5-dsc10.jpg

This blog article is one of many that I’ve written and will be writing about the new features in PowerShell version 5. You can find my other blog articles on PowerShell version 5 here.

µ