Here's a bit of some background. I'm trying to determine the reboot status of a windows server. I'm using the following script:
https://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542
I've included that in the Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE folder.
I then wrote a new script. See attached below. I'm dot sourcing the original script to use that as a function.
Param ( [String]$Computer ) ."C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\Get-PendingRebootFunction.ps1" # Begin PRTG section $Results = Get-PendingReboot -ComputerName $Computer foreach ($Result in $Results){ if ($Result.CBServicing -eq $true){ Write-Output "4:Reboot Pending" Exit 4; } elseif($Results.WindowsUpdate -eq $true){ Write-Output "4:Reboot Pending" Exit 4; } elseif ($Results.CCMClientSDK){ if ($Results.CCMClientSDK -eq $true){ Write-Output "4:Reboot Pending" Exit 4; } } elseif ($Results.PendFileRename -eq $true){ Write-Output "4:Reboot Pending" Exit 4; } elseif ($Results.PendFileRenVal){ Write-Output "4:Reboot Pending" Exit 4; } elseif ($Results.RebootPending -eq $true){ Write-Output "4:Reboot Pending" Exit 4; } else{ Write-Output "0:OK" Exit 0; } }
If I run this on the PRTG server, against a machine that has a pending reboot, then I get a true value when I look at all of the values in $results.
If I try to use this with PRTG, the %host value from the device is being passed correctly, I've written the value $computer out to a text file. However, when used with the function, it's as if it's checking the PRTG server (which doesn't have a reboot pending).
So, when running from PowerShell on PRTG against a machine that has a pending reboot, I see the following values:
Computer: Computer1 CBServicing : True WindowsUpdate : True CCMClientSDK : False PendFileRename : False PendFileRenVal : RebootPending : True
When I run this as a custom sensor, I get the following output:
Computer: Computer1 CBServicing : False WindowsUpdate : False CCMClientSDK : False PendFileRename : False PendFileRenVal : RebootPending : False
I'm confused by the differences here. Why would the results be different? When running within PowerShell? I'm wondering if this is a context thing here.
The use of the function basically does a check against the machine from the PRTG server. Am I approaching this the wrong way?
Add comment