Hello, running the following script and receiving this error when trying to get information from remote servers. I can run the script myself and don't receive any errors, its only PRTG that is returning the error so I believe that it has something to do with the way PRTG is running the script. I have the correct credentials put in for the sensor, but other than that i'm not sure what could be the issue.

$hostname = "yourhostname"

Invoke-Command -ComputerName $hostname{
$today=(Get-Date)
$dateshift=(Get-Date).AddHours(-12)
$EventError=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Error"}
$EventWarning=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Warning"}
$EventOK=Get-WinEvent -LogName Microsoft-Windows-Backup| Where-Object {$_.TimeCreated -gt $dateshift} | Where-Object {$_.LevelDisplayName -eq "Information"}

$backupsets=Get-WBBackupSet
$lastbackup=(Get-Date)-($backupsets.BackupTime |Measure-Object -Maximum |Select-Object -ExpandProperty Maximum)
$lastbkround=[math]::Floor($lastbackup.TotalHours)

$x = [string] $($EventError.Count)+":OK"
Write-Host $x



Exit 0
} 

Article Comments

Hello,

Thank you very much for the KB-Post. Is the execution policy set to unrestricted (at least for testing)? Also, does it help to run the PRTG Probe Service under a domain admin account (instead of LOCAL SYSTEM)?

best regards.


Aug, 2017 - Permalink

Thank you for replying, I changed the policy to unrestricted just to test and still get the same error. I can run the script just fine myself so I don't believe is has to do with that, and I am running the probe with domain admin credentials.


Aug, 2017 - Permalink

Can you share a screenshot please, showing where the credentials are set for the Probe?


Aug, 2017 - Permalink

It didn't dawn on me until last night that the credentials you were talking about and what I was referring to were different. After changing the actual probe service credentials to the domain admin, the script works as it is suppose to! Thank you!


Aug, 2017 - Permalink