We are wanting to monitor whether a server has a pending reboot or not. To do so we have a script that sets a registry key to 1 if a reboot is needed or 0 if not. I found a powershell script for a similar need and modified it, but I can't seem to get it to work. It is returning a blank ' ' and showing unknown when testing. Is there something I'm missing?
Arguments:
HKLM:\SOFTWARE\SW-Reg-Check\PendingReboot,1
param(
[string]$reg,
[string]$Key,
$target_value
)
$reg_value = Get-ItemProperty $reg -name $Key
Write-Host "Message: '$reg' is currently set to '$reg_value'"
if ($reg_value -match "$key=$target_value") {
Write-Host "Statistic: 0"
} else {
Write-Host "Statistic: 1"
}
Exit 0