I'm having issues with the following PowerShell script used to report back on the number of files in a UNC path with a specified extension:

param([string]$P=0, [string]$Ext=0, [int32]$Total=0)

$Total =@(Get-ChildItem $P -filter "$Ext").Count;

if ($Total.Count -lt 10) {
    Write-output "0:ok";
	}else{ 
    Write-output "4:not ok";
 }	

This runs fine as a standalone PowerShell script, but I get the following back from PRTG:

Response not wellformed: "(AuthorizationManager check failed. At line:1 char:2 + & <<<< 'C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\1-File Count.ps1' -p \\128.1.16.14\c$\temp\ -ext *.txt; exit $LASTEXITCODE + CategoryInfo : NotSpecified: (:) [], PSSecurityException + FullyQualifiedErrorId : RuntimeException )" (code: PE132)

I've tried all sorts of variations of 'Write-output', 'Write-host' and various forms of output and I just can't get it to work. Can anyone help?

Many thanks

Si


Article Comments

Hi Simon,

Please execute the following command in a PowerShell (x86) with administrative privileges: Set-ExecutionPolicy Unrestricted

The script should work then :)

Kind regards, Stephan


Jul, 2014 - Permalink

Hi Stephan,

I've already got the Execution Policy set as you suggested.

Regards

Si


Jul, 2014 - Permalink

Do other scripts work? Can you create a script like this and test it:

Write-Host "0:Everything okay";
Exit 0;

Do you get the same error there? Then it would indicate that your PowerShell profile is corrupted...


Jul, 2014 - Permalink

I have the same issue, but I can use Write-host, I need use a Write-Host and the sensor show Response not wellformed.

Anyone has any update how format accept by prtg with Write-OutPut


Dec, 2020 - Permalink

Are you using the correct output with the correct Sensor? What does your output look like? Advanced Sensors always expect XML/JSON output, normal script Sensors expect <counter>:<message>.


Dec, 2020 - Permalink