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:
1configuration iSCSI {
2
3 param (
4 [Parameter(Mandatory)]
5 [string[]]$ComputerName
6 )
7
8 node $ComputerName {
9
10 WindowsFeature MultipathIO {
11 Name = 'Multipath-IO'
12 Ensure = 'Present'
13 }
14
15 Service iSCSIService {
16 Name = 'MSiSCSI'
17 StartupType = 'Automatic'
18 State = 'Running'
19 }
20
21 }
22}
Run the configuration specifying the computer names to create MOF files for:
1iSCSI -ComputerName SQL01, WEB01
In the preview version of PowerShell version 5, the New-DscCheckSum
cmdlet now has a WhatIf
parameter:
1New-DscCheckSum -ConfigurationPath .\iSCSI -WhatIf
A Confirm
parameter has also been added to the New-DscCheckSum
cmdlet:
1New-DscCheckSum -ConfigurationPath .\iSCSI -Confirm
Verify the state of the specific features and services on the servers:
1Invoke-Command -ComputerName SQL01, WEB01 {
2 Get-WindowsFeature -Name Multipath-IO
3} | Select-Object -Property PSComputerName, Name, Installed
4
5Invoke-Command -ComputerName SQL01, WEB01 {
6 Get-CimInstance -ClassName Win32_Service -Filter "Name = 'MSiSCSI'"
7} | Select-Object -Property PSComputerName, Name, State, StartMode
Apply the DSC configuration:
1Start-DscConfiguration -ComputerName SQL01, WEB01 -Path .\iSCSI -Wait -Verbose
Check the status of the features and services again:
1Invoke-Command -ComputerName SQL01, WEB01 {
2 Get-WindowsFeature -Name Multipath-IO
3} | Select-Object -Property PSComputerName, Name, Installed
4
5Invoke-Command -ComputerName SQL01, WEB01 {
6 Get-CimInstance -ClassName Win32_Service -Filter "Name = 'MSiSCSI'"
7} | Select-Object -Property PSComputerName, Name, State, StartMode
Test the DSC configuration using the Test-DscConfiguration
cmdlet:
1Test-DscConfiguration -CimSession SQL01, WEB01
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:
1Test-DscConfiguration -CimSession WEB01 -Detailed
1Test-DscConfiguration -CimSession WEB01 -Detailed | Select-Object -ExpandProperty ResourceID
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.
µ