Hello,
I have created a NON XML custom EXE/Script sensor that uses a PowerShell script to count the number of files without a .old extension older than 2 hours in a folder on a remote machine. The only parameter I'm specifying is %host:
%host
$UnprocessedFiles = Invoke-Command -ComputerName $args[0] -ScriptBlock {Get-ChildItem -File -Path 'D:\SMS Folders\Inbound CAD'} $UnprocessedFilesError = $UnprocessedFiles | Where-Object {$_.Name -notmatch ".old" -and $_.LastWriteTime -lt $(Get-Date).AddHours(-2)} IF($UnprocessedFilesError){ $Count = ($UnprocessedFilesError | Measure-Object).Count Write-Host "$Count`: $Count Unprocessed File(s) found in D:\SMS Folders\Inbound CAD. SMS is not processing inbound CAD files." exit 2 } IF(!$UnprocessedFilesError){ Write-Host "0:No unprocessed CAD files found" exit 0 }
The script works when run from the probe server by my user account as long as I specify the computer name in the invoke-command.
When I set it up as a sensor I have the channel for my Count set as an integer. The value it returns is the count of files older than 2 hours.
I have ensured the execution policy is set to bypass.
When I set the sensor to run in the security context of the probe service account (local system) it can't run the invoke-command because its running as local system so it shows the OK result on the sensor. However, I can see the count channel show up with a value of 0 and I can see the execution time channel with the time it took to run the script.
When I run the sensor in the security context of the parent device (prtg service account with local admin to the target machine) the script runs successfully and I can see it change the sensor status to error and set the expected last message... But the Count channel doesn't show up on the sensor and the two channels I can see Downtime and Execution Time show "No Data".
If I break the sensor by setting it to run as the probe service account for one run the Count channel does show up but as soon as I set it back to run under the service account all my channels including the count show up as "No Data".
I've tried recreating the sensor.
I tried running the script under the PRTG Service account (local system) and using the %windowsuser and %windowspassword place holders to pass the credentials to a PSCredential and used it in the invoke-command with the same result.
I'm not sure what else to try or what the problem could be. If I can't get it working I'll try the XML Advanced sensor but I'd prefer not to if I can get this working.
Thanks for any help you can provide.
Add comment