What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Problems with Powershell script

Votes:

0

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?

hyper-v powershell prtg

Created on Nov 14, 2012 1:09:50 PM

Last change on Nov 14, 2012 5:35:03 PM by  Torsten Lindner [Paessler Support]



7 Replies

Votes:

0

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.

Created on Nov 14, 2012 5:36:33 PM by  Torsten Lindner [Paessler Support]



Votes:

0

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.

Created on Nov 15, 2012 7:14:37 AM



Votes:

0

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.

Created on Nov 15, 2012 4:36:43 PM by  Torsten Lindner [Paessler Support]



Votes:

0

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?

Created on Nov 16, 2012 11:42:18 AM



Votes:

0

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.

Created on Dec 4, 2012 7:39:59 AM



Votes:

0

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

Created on Dec 4, 2012 3:31:24 PM by  Torsten Lindner [Paessler Support]



Votes:

2

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".

Created on Feb 8, 2017 5:17:50 PM




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.