Trying to get PRTG to execute the below powershell script under a Custom EXE/XML Advanced sensor. Never get a result in PRTG for 'State', however the script runs fine in powershell and receives the below successful output when run in PS;
(NOTE - 6=good, 7=fail)
***PS C:\<PRTGDir>\EXEXML> .\execute-remote-task-no-function.ps1 -RemoteSvr XXX -DestPing xxx.xxx.xxx.xxx <prtg> <result> <channel>State</channel> <value>6</value> </result> </prtg>***
With 'Write results to disk..' on, I get the below error sometimes in the log, it's my only clue to the issue;
***"This sensor requires the powershell 2.0 (or higher) to be installed on the probe system. (new-object : The term 'new-object' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:36 + if ($PSVersionTable.PSVersion -ge (new-object 'Version' 5,0)) { Import-Module Mi ... + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (new-object:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException get-content : The term 'get-content' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXEXML\execute-remote-task-no-function.ps1:13 char:13 + $password = get-content "$secure\svdiautomation.pwd" | convertto-securestring + ~~~~~~~~~~~ + C) (code: PE181)"***
The Custom EXE/XML Advanced sensor is configured with the below parameters to pass to the script;
*'-RemoteSvr au2106sp0339 -DestPing 10.9.212.42'*
The script works absolutely fine, when I launch it directly from Powershell under 'Run-as' the same Windows account used on the sensor's parent for 'Windows Systems'.
Script below;
***param([string]$remotesvr,[string]$pingdest) #=============================================================================================================================================== # Script Purpose: | Execute tasks on remote servers, retrieve data # Date Implemented: | 03/03/2016 # Last Modified: | 03/03/2016 # Version: | 0.1 # Author: | XXXXX # Contact: | XXXXXXX #=============================================================================================================================================== #Global Variables $secure = 'd:\scripts\secure\' $userid = "XXXXXXXXXXXX" $password = get-content "$secure\xxxxxxxxx.pwd" | convertto-securestring $credential = New-Object System.Management.Automation.PsCredential $userid, $password #$remotesvr = "XXXXXXXXXX" #$destping = "xxx.xxx.xxxx.xxxx" #=============================================================================================================================================== #Execute $session = New-PSSession -ComputerName $remotesvr -Credential $credential $result = Invoke-Command -Session $session -Scriptblock {Test-Connection -Computername 1"$($args[0])" -count 1 -quiet} -Argumentlist $pingdest Remove-PsSession $session.id if ($result -eq $true) {$value = "6"} else {$value = "7"} echo "<prtg>" echo "<result>" echo "<channel>State</channel>" echo "<value>$value</value>" echo "</result>" echo "</prtg>"***
Environment: Win2k8 with Powershell 3.0 PRTG: 16.1.21.1422
Add comment