@@ -48,17 +48,15 @@ function Test-DscPropertyState
4848 }
4949 elseif (
5050 $Values.DesiredValue -is [Microsoft.Management.Infrastructure.CimInstance []] `
51- -or $Values.DesiredValue -is [System.Array ] -and $Values.DesiredValue [0 ] -is [Microsoft.Management.Infrastructure.CimInstance ]
51+ -or $Values.DesiredValue -is [System.Array ] -and $Values.DesiredValue [0 ] -is [Microsoft.Management.Infrastructure.CimInstance ]
5252 )
5353 {
5454 if (-not $Values.ContainsKey (' KeyProperties' ))
5555 {
56- $errorMessage = $script :localizedData.KeyPropertiesMissing
57-
58- New-InvalidOperationException - Message $errorMessage
56+ New-InvalidOperationException - Message $script :localizedData.KeyPropertiesMissing
5957 }
6058
61- $propertyState = @ ()
59+ $propertyState = [ System.Collections.ArrayList ]::new ()
6260
6361 <#
6462 It is a collection of CIM instances, then recursively call
@@ -80,23 +78,20 @@ function Test-DscPropertyState
8078
8179 if ($currentCimInstance.Count -gt 1 )
8280 {
83- $errorMessage = $script :localizedData.TooManyCimInstances
84-
85- New-InvalidOperationException - Message $errorMessage
81+ New-InvalidOperationException - Message $script :localizedData.TooManyCimInstances
8682 }
8783
8884 if ($currentCimInstance )
8985 {
90- $keyCimInstanceProperties = $currentCimInstance.CimInstanceProperties |
91- Where-Object - FilterScript {
86+ $keyCimInstanceProperties = $currentCimInstance.CimInstanceProperties.Where ({
9287 $_.Name -in $Values.KeyProperties
93- }
88+ })
9489
9590 <#
9691 For each key property build a string representation of the
9792 property name and its value.
9893 #>
99- $keyPropertyValues = $keyCimInstanceProperties.ForEach ({' {0}="{1}"' -f $_.Name , ($_.Value -join ' ,' )})
94+ $keyPropertyValues = $keyCimInstanceProperties.ForEach ({ ' {0}="{1}"' -f $_.Name , ($_.Value -join ' ,' ) })
10095
10196 Write-Debug - Message (
10297 $script :localizedData.TestingCimInstance -f @ (
@@ -107,16 +102,15 @@ function Test-DscPropertyState
107102 }
108103 else
109104 {
110- $keyCimInstanceProperties = $desiredCimInstance.CimInstanceProperties |
111- Where-Object - FilterScript {
105+ $keyCimInstanceProperties = $desiredCimInstance.CimInstanceProperties.Where ({
112106 $_.Name -in $Values.KeyProperties
113- }
107+ })
114108
115109 <#
116110 For each key property build a string representation of the
117111 property name and its value.
118112 #>
119- $keyPropertyValues = $keyCimInstanceProperties.ForEach ({' {0}="{1}"' -f $_.Name , ($_.Value -join ' ,' )})
113+ $keyPropertyValues = $keyCimInstanceProperties.ForEach ({ ' {0}="{1}"' -f $_.Name , ($_.Value -join ' ,' ) })
120114
121115 Write-Debug - Message (
122116 $script :localizedData.MissingCimInstance -f @ (
@@ -138,7 +132,7 @@ function Test-DscPropertyState
138132 }
139133 elseif ($Values.DesiredValue -is [Microsoft.Management.Infrastructure.CimInstance ])
140134 {
141- $propertyState = @ ()
135+ $propertyState = [ System.Collections.ArrayList ]::new ()
142136
143137 <#
144138 It is a CIM instance, recursively call Test-DscPropertyState for each
@@ -186,21 +180,21 @@ function Test-DscPropertyState
186180 {
187181 Write-Debug - Message $script :localizedData.ArrayDoesNotMatch
188182
189- $arrayCompare |
190- ForEach-Object - Process {
191- if ($_.SideIndicator -eq ' =>' )
192- {
193- Write-Debug - Message (
194- $script :localizedData.ArrayValueIsAbsent -f $_.InputObject
195- )
196- }
197- else
198- {
199- Write-Debug - Message (
200- $script :localizedData.ArrayValueIsPresent -f $_.InputObject
201- )
202- }
183+ foreach ($item in $arrayCompare )
184+ {
185+ if ($item.SideIndicator -eq ' =>' )
186+ {
187+ Write-Debug - Message (
188+ $script :localizedData.ArrayValueIsAbsent -f $item.InputObject
189+ )
203190 }
191+ else
192+ {
193+ Write-Debug - Message (
194+ $script :localizedData.ArrayValueIsPresent -f $item.InputObject
195+ )
196+ }
197+ }
204198
205199 $returnValue = $false
206200 }
@@ -215,17 +209,7 @@ function Test-DscPropertyState
215209
216210 $returnValue = $false
217211
218- $supportedTypes = @ (
219- ' String'
220- ' Int32'
221- ' UInt32'
222- ' Int16'
223- ' UInt16'
224- ' Single'
225- ' Boolean'
226- )
227-
228- if ($desiredType.Name -notin $supportedTypes )
212+ if ($desiredType.Name -notin ' String' , ' Int32' , ' UInt32' , ' Int16' , ' UInt16' , ' Single' , ' Boolean' )
229213 {
230214 Write-Warning - Message ($script :localizedData.UnableToCompareType -f $desiredType.Name )
231215 }
0 commit comments