Florian,
I was able to fix the issue outside of PRTG, however I can still reproduce the issue in PRTG. I have concluded that PRTG is not transferring the script (your version above, or mine) to the remote system and running it.
I created this script and have it as a Sensor on the local PRTG Server. That server runs only PRTG and no other applications:
$RegPathRebootPending = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired"
$RebootPending = (Test-Path $RegPathRebootPending)
If ($RebootPending) {
# $true
Write-Host "2:There is a reboot Pending"
Exit 2
}
Else {
Write-Host "0:Life is good! No Reboots are Pending"
Exit 0
}
}
The script always reports that the status is "good" regardless of the Registry key being present or not.
If I add "Write-Host "3:Hello World!", then PRTG reports "Hello World."
I have about 100 servers and this solution is very painful, but it works. write the script as such:
$RemoteComputerName = "RDPServer-00"
Invoke-Command -computername $RemoteComputerName -ScriptBlock {$RegPathRebootPending = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired"
$RebootPending = (Test-Path $RegPathRebootPending)
If ($RebootPending) {
# $true
Write-Host "2:There is a reboot Pending"
Exit 2
}
Else {
Write-Host "0:Life is good! No Reboots are Pending"
Exit 0
}
}
Then save it to a ps1 file. In this case, the script name is RDPServer-00. Add a custom exe sensor that points to that PS1 file under RDPServer-00 and set it to "use windows credentials of parent device" and it will run as expected and report accurately.
Some things that don't work:
- Regardless of the Result Handling setting, Log files do not generate.
- Moving "-computername localhost" or in this case "-computername RDPServer-00" to the Parameters in PRTG does not work. I tested it with " marks and ' marks.
- Using localhost as the -computername parameter in the script does not work.
- The CheckRegistry script from the PRTG website does not work.
A theory:
After running and working with all of the Demo Scripts provided by PRTG with the installation and then running every PowerShell script that I could find on the PRTG website, I believe there are 2 problems in PRTG.
- The script is not actually being transferred to the server where the Sensor is configured. Therefore it is returning whatever it has in Memory as the result.
- The Test-Path command returns only True or False. PRTG doesn't know how to handle the result and it simply ignores the conditional logic in the script.
Wolfgang
Add comment