Running PRTG 12.4.6.3230 on Windows server 2012 and have a powershell script that works fine att the PRTG/probe server. Set-ExecutionPolicy Unrestricted on the PRTG/probe sever

**
$replikationstatus = Get-VMReplication -ComputerName hv_rep01 | where {$_.health -ne "Normal"}
if ($replikationstatus.count -eq 0) { Write-host "Replikeringsstaus OK",":OK" 
exit 0 }
else {Write-host "Replikeringstatus fel","Error"
exit 2}
**

When I run the script as Custom EXE/Script I dont get anny error, just an 'Last Message' that says 'UnauthorizedAccess' with last result 0 #

What am I missing with rinning powershell in PRTG?


Article Comments

Hello,

two things, please bear in mind that the PRTG Probe will call the 32bit Powershell, this is important for setting the ExecutionPolicy. Also, please note that the user context may be a different when the script is executed by the Probe (by default this will be the "LOCAL SYSTEM"-account) not your account when running the script manually.

best regards.


Nov, 2012 - Permalink

Hi.

Ok, how should the ExecutionPolicy be set to work with PRTG then? I think the actual commands should be great help to alla PRTG users.

In the probe there is two options regarding security; Security Context

  • Use security context of probe service
  • Use Windows credentials of parent device

I have tried both but no difference. I even tried an account that is Domain Admin without luck running Powershell in PRTG.

If you have support for Powershell scripts in PRTG a guide, step by step, would be appreciated.


Nov, 2012 - Permalink

Execution policy set to unrestricted should be fine, but as I mentioned, very often this is only changed for the 64bit Powershell, while PRTG actually only used the 32bit Powershell.


Nov, 2012 - Permalink

We are moving forward.

After Execution Policy was set for x86 some kind of script actually run. If I run the script manually on the Powershell console of the PRTG server the script works fine, returns errorlevel and Last Message.

When I run the script trough PRTG the logic of the script don’t work and therefor I always get errorlevel 0 and the Last Message “:OK”.

The IF statement in the code does work and I get the Last Message that the script defines but the variable $replikationstatus always seems to be empty - the fault must be in $replikationstatus = Get-VMReplication -ComputerName hv_rep01 | where {$_.health -ne "Normal"} But it work when I run in on the console, any tips?


Nov, 2012 - Permalink

The question is still unanswered, how do we, the customers, run powershell scripts that return values to the PRTG server. If you, Paessler, know how to do this a step by step guide should not take longer than 10 minutes to write down and save us, the customer, a lot of time and get value of the product we bought.


Dec, 2012 - Permalink

That's already documented in your own PRTG under "Setup"->"PRTG API"->"Custom Sensors".


Dec, 2012 - Permalink

Another thing that got me, which caused this same "UnauthorizedAccess" problem is that I had copied the Powershell script to the PRTG server. But, I had to right-click on the file's properties and click "Unblock".


Feb, 2017 - Permalink