Desired Configuration Management - Trigger Evaluation Remotely
Either I haven't seen it posted elsewhere, or can't find it in the SDK, but I had a need to trigger DCM evaluations on clients. Here's the code I ended up with. It could I'm sure be cleaner, or there's already a documented way to do this, but it's working for me so I thought I'd share it. It could be easily made into a right-click extension, or added as a button to Ron's Console. Let me know if anyone needs this as a button on Ron's Web Console 3.21; I could throw it together.
On Error Resume Next
CompName = Wscript.Arguments(0)
If compname = "" Then
CompName = InputBox("Input a Computer name or IP", "Computer Name",CompName)
End If
err.clear
set DCMInvoke = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
CompName & "\root\ccm\dcm:SMS_DesiredConfiguration")
if err.number <> 0 then
msgbox "unable to access " & CompName & vbcr &_
"Error: " & err.description,,"SMS DCM Trigger Evaluation"
else
Set objSWbemServices = GetObject("winmgmts:\\" & CompName & "\root\ccm\dcm")
Set colSWbemObjectSet = objSWbemServices.ExecQuery("SELECT * FROM SMS_DesiredConfiguration")
For Each objSWbemObject In colSWbemObjectSet
DCMInvoke.TriggerEvaluation objSWbemObject.Name,objSWbemObject.Version
Next
end if