# Monitor SOAP request with powershell

**URL:** <https://community.squaredup.com/t/monitor-soap-request-with-powershell/1616>\
**Category:** Dashboard Server\
**Tags:** powershell-monitorin\
**Created:** [November 16, 2021, 1:37pm UTC](https://community.squaredup.com/t/monitor-soap-request-with-powershell/1616 "2021-11-16T13:37:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucvb](https://community.squaredup.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@lucvb](https://community.squaredup.com/u/lucvb)\
**Post date:** [November 16, 2021, 1:37pm UTC](https://community.squaredup.com/t/monitor-soap-request-with-powershell/1616/1 "2021-11-16T13:37:27Z")

</div>

Hi,

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?

param([string]$Arguments)

#test

# $Arguments = “[https://pvx2cc1n1.ux.pv.be/cc/ws/gw/webservice/cc/MessagingToolsAPI?WSDL;324](https://pvx2cc1n1.ux.pv.be/cc/ws/gw/webservice/cc/MessagingToolsAPI?WSDL;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”  
}

$PropertyBag.AddValue(“WebserviceStatus”,$WebserviceStatus)  
$PropertyBag.AddValue(“WebserviceEndpoint”,$WebserviceEndpoint)  
$PropertyBag.AddValue(“MessageQueueStatus”,$MessageQueueStatus)

$PropertyBag

#test

# $WebserviceStatus

# $WebserviceEndpoint

# $MessageQueueStatus

Kind regards,  
Luc

---

<div class="post-metadata">

**Author:** ![an\_evil\_penguin](https://community.squaredup.com/user_avatar/community.squaredup.com/an_evil_penguin/32/858_2.png) [@an\_evil\_penguin](https://community.squaredup.com/u/an_evil_penguin)\
**Post date:** [November 16, 2021, 4:26pm UTC](https://community.squaredup.com/t/monitor-soap-request-with-powershell/1616/2 "2021-11-16T16:26:18Z")

</div>

For debugging PowerShell I absolutely love [transcript logging](https://thesurlyadmin.com/2015/10/20/transcript-logging-why-you-should-do-it/).

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.

---

<div class="post-metadata">

**Author:** ![pchip](https://community.squaredup.com/letter_avatar_proxy/v4/letter/p/91b2a8/32.png) [@pchip](https://community.squaredup.com/u/pchip)\
**Post date:** [November 19, 2021, 4:39pm UTC](https://community.squaredup.com/t/monitor-soap-request-with-powershell/1616/3 "2021-11-19T16:39:13Z")

</div>

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](https://techcommunity.microsoft.com/t5/system-center-blog/how-to-analyze-a-workflow-when-the-opsmgr-workflow-analyzer/ba-p/348590)… 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!

---

<div class="post-metadata">

**Author:** ![lucvb](https://community.squaredup.com/letter_avatar_proxy/v4/letter/l/94ad74/32.png) [@lucvb](https://community.squaredup.com/u/lucvb)\
**Post date:** [November 23, 2021, 7:24am UTC](https://community.squaredup.com/t/monitor-soap-request-with-powershell/1616/4 "2021-11-23T07:24:13Z")

</div>

Thanks everyone, I’ve got this working now.
