Hi there,
I'm running into issues regarding PowerShell return values. I'm using a PS script to detect whether Windows processes are responding or not.
Here's the code:
Param( [string][Parameter(Mandatory=$True)]$p_name ) $check_result = [string](gps -name $p_name).Responding $check_result if($check_result -like "*False*"){ $exit_code = 4 write-host $exit_code":Error (At least one associated process is not responding)" exit 4 } elseif($check_result -notlike "*False*"){ $exit_code = 0 write-host $exit_code":OK (All associated processes are responding)" exit 0 }
For testing purposes, I'm opening a couple of instances of notepad or calc and suspend some of them in Resource Monitor. The script itself is working fine and I get the expected results, but only as long as I run it directly on the server in the "normal" PowerShell or ISE, respectively. But when I add it as a sensor, it always returns "All associated processes are responding", no matter whether there really are any processes not responding or not. It seems like it always immediately jumps to the "elseif" part.
I'm running PRTG on Windows Server 2016. Can you please let me know, if my code is just not right (I'm quite new to PowerShell) or I haven't understood something correctly stated in the manual? I'm sure, I must have overlooked something ...
Thanks in advance and best regards, Matthias
Add comment