Monitor SOAP request with powershell


I try to make a 3 state monitor with powershell to monitor a SOAP request, where it needs to be critical, when de requeste value (MessageQueueStatus) is wrong, when there is a problem with the monitor (url, …) I need to get a warning (WebserviceStatus).
The powershell works in the ISE, but in SCOM it seems not to be working.
Any ideas?



$Arguments = “;324

$Parameters = $Arguments.Split(";")
$Wsdl = $Parameters[0]
$MessageQueueID = $Parameters[1]
$WebserviceStatus = “”
$WebserviceEndpoint = “”
$MessageQueueStatus = “”

$ScomAPI = New-Object -comObject “MOM.ScriptAPI”
$PropertyBag = $ScomAPI.CreatePropertyBag()

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

try {
$Webservice = New-WebServiceProxy -Uri $Wsdl
$Authentication = new-Object -TypeName Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1vice_cc_MessagingToolsAPI_WSDL.authentication
$Authentication.username = ‘user’
$Authentication.password = ‘password’
$Webservice.authenticationValue = $Authentication

$WebserviceStatus = "OK"
$WebserviceEndpoint = $Webservice.Url
$MessageQueueStatus = $Webservice.getDestinationStatus($MessageQueueID)

catch {
$WebserviceStatus = “Not OK”







Kind regards,

For debugging PowerShell I absolutely love transcript logging .

Typically I include an overridable property or look for a Registry key on the host, if true it does logging and sends it to a defined folder ($Env:Temp if I’m being lazy). I’ll also then set $VerbosePreference to ‘continue’ and scatter Write-Verbose about the script to let me know what is going on, what variables are populated and so on. If you’re getting errors you’ll capture them, if you crash out you get a rough idea of what was completed successfully, so on.

I’ve been bitten more times than I care to remember by the ISE caching some variable somewhere that wasn’t present on execution.

Agree with An_Evil_Penguin, logs are your friend. I have done REST-API monitoring from SCOM on Apple and AirWatch endpoints (both of which require authentication), so there is no question that what you’ve asked can work within SCOM. I personally store all my script logs in the EventLog so not to require log maintenance and my scripts are very verbose.

If logs aren’t sufficient, try workflow troubleshooting… and last tip, search the OpsMgr event log on your agent for EventID 22406 and the name of your script. I recently spent days trying to make a workflow work, just to figure out (with that event) that the script wasn’t even starting!

Thanks everyone, I’ve got this working now.

1 Like