Reference Guide

'*** Check that the right executable was used to run the script and that all parameters were passed
If (LCase(Right(WScript.FullName, 11)) = "wscript.exe" ) Or _
(Wscript.Arguments.Count < 1) Then
Call Usage()
WScript.Quit
End If
'*** Initialize variables
strNameSpace = "root/dcim/sysman"
strComputerName = WScript.Arguments(0)
strClassName = "DCIM_ComputerSystem"
returnValue = 0
'*** Retrieve the instance of DCIM_ComputerSystem class
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate," &_
"AuthenticationLevel=pktprivacy}\\" & strComputerName & "\" &_strNameSpace)
Set ColSystem=objWMIService.execquery ("Select * from " & strClassName)
For each objInstance in ColSystem
Set oInParams=
objInstance.Methods_("RequestStateChange").InParameters.SpawnInstance_
oInParams.RequestedState = 3
Set returnValue = objInstance.ExecMethod_("RequestStateChange", oInParams)
Next
'*** If any errors occurred, let the user know
If Err.Number <> 0 Then
WScript.Echo "Operation failed."
End If
'*** Sub used to display the correct usage of the script
Sub Usage()
Dim strMessage
strMessage = "incorrect syntax. You should run: " & vbCRLF & _
"cscript.exe /nologo SampleShutdown.vbs <systemname>"
WScript.Echo strMessage
End Sub
'==========================================================================
' End
'==========================================================================
413