All,
I am working on a script that monitors the windows update service weather its running or not. We have some issues where we need to know if this service is running and flag it to alert. I have made some progress on the script to actually use the placeholder details of PRTG to auth correctly to the remote server but I just cannot get it to change the sensor red to alert with the exit codes. I can manually stop or start the service on the remote box and see it change in PRTG but it just will just not set it to Alert or red when the exit code is 2. It sees my messages in PRTG but just wont change the sensor.
Code
C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\WUServiceStatus.ps1: Param( [string]$WHost, [string]$Username, [string]$Password ) #create credentials $SecPassword = $Password | ConvertTo-SecureString -AsPlainText -force $cred = new-object -typename System.Management.Automation.PSCredential ($Username, $SecPassword) $ret = invoke-command -computer $WHost -Credential $cred -ScriptBlock { # search for process $pr = get-service wuauserv | Select -ExpandProperty "Status" # If Update service running return error if ($pr -match "Running") { Write-OutPut "2:Windows Update RUNNING"; Exit 2 } ELSE { Write-OutPut "0:Windows Update STOPPED"; Exit 0 } } # end script block $ret
Custom EXE/Script sensor Parameters settings:
-UserName %windowsdomain\%windowsuser -Password "%windowspassword" -WHost %host
Can anyone advise how to get this to actually set PRTG to alert status when the Exit 2 code is found if the windows update service is running?
I feel like it could be an issue with the invoke command not returning the exit code correctly but I am not a PS GURU and not 100% sure what to look for to understand why.
Add comment