@@ -134,16 +134,20 @@ function GetCimSpace {
134
134
}
135
135
' Set' {
136
136
$wmi_instance = ValidateCimMethodAndArguments - DesiredState $r
137
- InvokeCimMethod - CimInstance $ wmi_instance.CimInstance - MethodName $wmi_instance .MethodName - Arguments $wmi_instance .Parameters
137
+ InvokeCimMethod @ wmi_instance
138
138
139
- $result + = [PSCustomObject ]@ {
139
+ $addToActualState = [dscResourceObject ]@ {
140
140
name = $r.name
141
141
type = $r.type
142
- properties = $null # Set operation does not return properties
142
+ properties = $null
143
143
}
144
+
145
+ $result += $addToActualState
144
146
}
145
147
' Test' {
146
148
# TODO: implement test
149
+ " Test operation is not implemented for WMI/CIM methods." | Write-DscTrace - Operation Error
150
+ exit 1
147
151
}
148
152
}
149
153
}
@@ -164,6 +168,12 @@ function ValidateCimMethodAndArguments {
164
168
exit 1
165
169
}
166
170
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
+
167
177
$className = $DesiredState.type.Split (" /" )[-1 ]
168
178
$namespace = $DesiredState.type.Split (" /" )[0 ].Replace(" ." , " /" )
169
179
@@ -176,6 +186,7 @@ function ValidateCimMethodAndArguments {
176
186
177
187
foreach ($param in $parameters.psobject.Properties.name ) {
178
188
if ($cimClassParameters.Name -notcontains $param ) {
189
+ # Only warn about invalid parameters, do not exit as this allows to action to continue when calling InvokeCimMethod
179
190
" '$param ' is not a valid parameter for method '$methodName ' in class '$className '." | Write-DscTrace - Operation Warn
180
191
} else {
181
192
$arguments += @ {
@@ -186,14 +197,15 @@ function ValidateCimMethodAndArguments {
186
197
187
198
$cimInstance = GetWmiInstance - DesiredState $DesiredState
188
199
189
- $i = [ PSCustomObject ] @ {
200
+ return @ {
190
201
CimInstance = $cimInstance
191
- Parameters = $arguments
202
+ Arguments = $arguments
192
203
MethodName = $methodName
193
204
}
205
+ } else {
206
+ " '$className ' class not found in namespace '$namespace '." | Write-DscTrace - Operation Error
207
+ exit 1
194
208
}
195
-
196
- return $i
197
209
}
198
210
199
211
function InvokeCimMethod
0 commit comments