We are currently having a problem with a script sensor that leverages the citrix broker plugins to check if a machien is in maintenance mode, When testing the script on the PRTG server directly the output is showing correctly however the value of the output from within PRTG is showing incorrectly.

Do scripts within PRTG run differently in any way? potentially an issue with the variables?

Script:

asnp Citrix.broker*

function MaintenanceModeValue () {

$MaintenanceMode = Get-BrokerMachine -MachineName <machine name> -adminaddress <Delivery controller> | select InMaintenanceMode -ExpandProperty InMaintenanceMode

If ($MaintenanceMode -eq $False) { 
Write-Host "0:Maintenance Mode Disabled"; } 
Else { 
Write-Host "2:Maintenance Mode Enabled";  }
}

MaintenanceModeValue;

The output received is always "2:Maintenance Mode Enabled" despite what the actual value of InMaintenanceMode is. Also, If I change the equals factor to $True instead of $False the script still outputs "2:Maintenance Mode Enabled". this makes me believe that when the script runs in PRTG the $MaintenanceMode Variable is reporting back with something other than either true or false.

as mentioned before the script runs perfectly when running within powershell directly from the server that hosts PRTG

Is there a way that i can test the output of what PRTG is actually seeing when running the script?


Article Comments

Hi there,

Thank you for your Knowledge-Base post.

PRTG executes Powershell with the parameter -NoProfile.
Can you please try to start "powershell.exe -noprofile" and run your script again? Does this make any difference?

You can also set the option "EXE Result" to "Write EXE result to disk" in your sensor configuration. This will generate two files with the names "Result of Sensor $ID.txt" and "Result of Sensor $ID.Data.txt in the folder "%programdata%\Paessler\PRTG Network Monitor\Logs\sensors". $ID is replaced with the ID of your sensor. Please paste the results here and make sure that any confidential data is redacted beforehand.

Please also check the following Knowledge-Base articles about Custom PowerShell scripts:
- https://helpdesk.paessler.com/en/support/solutions/articles/76000041700-guide-for-powershell-based-custom-sensors
- https://helpdesk.paessler.com/en/support/solutions/articles/80145-custom-exe-powershell-script-running-on-core-not-target
- https://helpdesk.paessler.com/en/support/solutions/articles/69565-customer-powershell-script-returns-no-response


Kind regards,
Matthias Kupfer - Team Tech Support


Apr, 2020 - Permalink