Set oArgs = WScript.Arguments
if oArgs.Count < 3 Then
WScript.Echo "Fail to Receive all Parameters. Please Check."
WScript.Echo "Parameters Count:" & CStr(oArgs.Count)
If oArgs.Count > 0 Then
WScript.Echo "Parameters TargetComputer:" & oArgs(0)
else
WScript.Echo "Parameters TargetComputer: Missing"
End If
If oArgs.Count > 1 Then
WScript.Echo "Parameters OrchestrationName:" & oArgs(1)
else
WScript.Echo "Parameters OrchestrationName: Missing"
End If
If oArgs.Count > 2 Then
WScript.Echo "Parameters Option:" & oArgs(2)
else
WScript.Echo "Parameters Option: Missing"
End If
Wscript.Quit -1
End If
Sub ExecActionOnOrchestration()
Dim strMessage
Dim objInstSet, objInst
Dim strFQOrchestrationName
On Error Resume Next
Set objInstSet = GetWMICollection(strTargetComputer, strNamespace, strQuery)
'Check for error condition before continuing.
If Err <> 0 Then
PrintWMIErrorThenExit Err.Description, Err.Number
End If
'If found, execute action, otherwise print error and end.
If objInstSet.Count > 0 then
For Each objInst in objInstSet
strFQOrchestrationName = CStr(objInst.Properties_("Name").Value)
strFQOrchestrationName = strFQOrchestrationName & ", " & CStr(objInst.Properties_("AssemblyName").Value)
strFQOrchestrationName = strFQOrchestrationName & ", " & CStr(objInst.Properties_("AssemblyVersion").Value)
strFQOrchestrationName = strFQOrchestrationName & ", " & CStr(objInst.Properties_("AssemblyCulture").Value)
strFQOrchestrationName = strFQOrchestrationName & ", " & CStr(objInst.Properties_("AssemblyPublicKeyToken").Value)
'If the orchestration matches the one which needs to be Start/Stop
if strFQOrchestrationName = strOrchestrationName then
Select Case strOption
Case "1"
objInst.Start
strMessage = "The Orchestration was successfully Started."
Case "2"
objInst.Stop
strMessage = "The Orchestration was successfully Stopped."
Case "3"
objInst.Enlist
strMessage = "The Orchestration was successfully Enlisted."
Case "4"
objInst.Unenlist
strMessage = "The Orchestration was successfully Unenlisted."
End Select
If Err <> 0 Then
PrintWMIErrorThenExit strFQOrchestrationName & ":" & Err.Description, Err.Number
End If
End If
WScript.Echo
Next
Else
WScript.Echo "No Orchestration was found matching that Name."
End If
End Sub
Function GetWMICollection(TargetComputerToUse, strNamespace, strQuery)
Dim WbemSrv, WbemObjectSet
Set WbemSrv = Getobject("winmgmts:{impersonationLevel=impersonate}!\\" & TargetComputerToUse & strNamespace)
Set WbemObjectSet = WbemSrv.ExecQuery(strQuery)
Set GetWMICollection = WbemObjectSet
End Function
'This subroutine deals with all errors using the WbemScripting object. Error descriptions
'are returned to the user by printing to the console.
Sub PrintWMIErrorThenExit(strErrDesc, nErrNum)
On Error Resume Next
Dim objWMIError : Set objWMIError = CreateObject("WbemScripting.SwbemLastError")
If (TypeName(objWMIError) = "Empty" ) Then
WScript.Echo strErrDesc & " (HRESULT: " & Hex(nErrNum) & ")."
Else
WScript.Echo objWMIError.Description & "(HRESULT: " & Hex(nErrNum) & ")."
Set objWMIError = Nothing
End If
'bail out
WScript.Quit 0
End Sub
'=================================================================================
' Publish resulting performance data / Create events
'=================================================================================
Sub CreateEvent(strSource, lngEventID, lngEventType, strMsg, strSrcComputer)
CreateEventEx strSource, lngEventID, lngEventType, strMsg, strSrcComputer, True
End Sub
Sub CreateReportEvent(strSource, lngEventID, lngEventType, strMsg, strSrcComputer)
CreateEventEx strSource, lngEventID, lngEventType, strMsg, strSrcComputer, False
End Sub
Sub CreateEventEx(strSource, lngEventID, lngEventType, strMsg, strSrcComputer, blnIncScriptName)
Dim oAPI
Set oAPI = CreateObject("Mom.ScriptAPI")
Call oAPI.LogScriptEvent(strSource, lngEventID, lngEventType, strMsg)
End Sub </Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Script"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>