Set oArgs = WScript.Arguments
if oArgs.Count < 3 Then
Wscript.Quit -1
End If
strTargetComputer = oArgs(0)
strSendPortGroupName = oArgs(1)
strOption = oArgs(2)
strNamespace = "\ROOT\MicrosoftBizTalkServer"
strQuery = "SELECT * FROM MSBTS_SendPortGroup WHERE Name =""" & Replace(strSendPortGroupName, "\", "\\") & """"
ExecActionOnSendPortGroup
Sub ExecActionOnSendPortGroup()
Dim strMessage
Dim objInstSet, objInst
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
Select Case strOption
Case "1"
objInst.Start
strMessage = "The Send Port Group was successfully Started."
Case "2"
objInst.Stop
strMessage = "The Send Port Group was successfully Stopped."
Case "3"
objInst.Enlist
strMessage = "The Send Port Group was successfully Enlisted."
Case "4"
objInst.UnEnlist
strMessage = "The Send Port Group was successfully Unenlisted."
End Select
If Err <> 0 Then
PrintWMIErrorThenExit Err.Description, Err.Number
End If
WScript.Echo
Next
Else
WScript.Echo "No Send Port Group 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>