@@ -134,16 +134,20 @@ function GetCimSpace {
134134 }
135135 ' Set' {
136136 $wmi_instance = ValidateCimMethodAndArguments - DesiredState $r
137- InvokeCimMethod - CimInstance $ wmi_instance.CimInstance - MethodName $wmi_instance .MethodName - Arguments $wmi_instance .Parameters
137+ InvokeCimMethod @ wmi_instance
138138
139- $result + = [PSCustomObject ]@ {
139+ $addToActualState = [dscResourceObject ]@ {
140140 name = $r.name
141141 type = $r.type
142- properties = $null # Set operation does not return properties
142+ properties = $null
143143 }
144+
145+ $result += $addToActualState
144146 }
145147 ' Test' {
146148 # TODO: implement test
149+ " Test operation is not implemented for WMI/CIM methods." | Write-DscTrace - Operation Error
150+ exit 1
147151 }
148152 }
149153 }
@@ -164,6 +168,12 @@ function ValidateCimMethodAndArguments {
164168 exit 1
165169 }
166170
171+ # This is required for invoking a WMI/CIM method with parameters even if it is empty
172+ if (-not ($DesiredState.properties.psobject.properties | Where-Object - Property Name -EQ ' parameters' )) {
173+ " 'parameters' property is required for invoking a WMI/CIM method." | Write-DscTrace - Operation Error
174+ exit 1
175+ }
176+
167177 $className = $DesiredState.type.Split (" /" )[-1 ]
168178 $namespace = $DesiredState.type.Split (" /" )[0 ].Replace(" ." , " /" )
169179
@@ -176,6 +186,7 @@ function ValidateCimMethodAndArguments {
176186
177187 foreach ($param in $parameters.psobject.Properties.name ) {
178188 if ($cimClassParameters.Name -notcontains $param ) {
189+ # Only warn about invalid parameters, do not exit as this allows to action to continue when calling InvokeCimMethod
179190 " '$param ' is not a valid parameter for method '$methodName ' in class '$className '." | Write-DscTrace - Operation Warn
180191 } else {
181192 $arguments += @ {
@@ -186,14 +197,15 @@ function ValidateCimMethodAndArguments {
186197
187198 $cimInstance = GetWmiInstance - DesiredState $DesiredState
188199
189- $i = [ PSCustomObject ] @ {
200+ return @ {
190201 CimInstance = $cimInstance
191- Parameters = $arguments
202+ Arguments = $arguments
192203 MethodName = $methodName
193204 }
205+ } else {
206+ " '$className ' class not found in namespace '$namespace '." | Write-DscTrace - Operation Error
207+ exit 1
194208 }
195-
196- return $i
197209}
198210
199211function InvokeCimMethod
0 commit comments