2022-10-09 19:16:32 +02:00
|
|
|
|
<#
|
2022-10-04 16:09:27 +02:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Check for pending reboots
|
|
|
|
|
.DESCRIPTION
|
|
|
|
|
This PowerShell script checks different registry keys and values to determine if a reboot is pending.
|
|
|
|
|
.EXAMPLE
|
|
|
|
|
./check-pending-reboot.ps1
|
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
|
|
|
|
function Test-RegistryValue { param([parameter(Mandatory=$true)][ValidateNotNullOrEmpty()]$Path, [parameter(Mandatory=$true)] [ValidateNotNullOrEmpty()]$Value)
|
2022-10-11 20:13:04 +02:00
|
|
|
|
try {
|
|
|
|
|
Get-ItemProperty -Path $Path -Name $Value -EA Stop
|
|
|
|
|
return $true
|
|
|
|
|
} catch {
|
|
|
|
|
return $false
|
|
|
|
|
}
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 12:34:06 +02:00
|
|
|
|
$Reason = ""
|
2022-10-04 16:09:27 +02:00
|
|
|
|
|
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry: '...\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry: '...\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry: '...\Windows\CurrentVersion\Component Based Servicing\RebootPending'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry: '...\Microsoft\ServerManager\CurrentRebootAttempts'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry: '...\Windows\CurrentVersion\Component Based Servicing' with 'RebootInProgress'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry: '...\Windows\CurrentVersion\Component Based Servicing' with 'PackagesPending'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
2022-10-11 20:20:42 +02:00
|
|
|
|
#if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
# $Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations'"
|
2022-10-11 20:20:42 +02:00
|
|
|
|
#}
|
2022-10-04 16:09:27 +02:00
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations2'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry '...\Windows\CurrentVersion\RunOnce' with 'DVDRebootSignal'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'JoinDomain'"
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") {
|
2022-10-29 17:34:15 +02:00
|
|
|
|
$Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'"
|
2022-10-09 12:34:06 +02:00
|
|
|
|
}
|
2022-10-24 11:43:54 +02:00
|
|
|
|
if ($Reason -ne "") {
|
|
|
|
|
"⚠️ Pending reboot ($($Reason.substring(2)))."
|
2022-10-09 12:34:06 +02:00
|
|
|
|
} else {
|
2022-10-24 11:43:54 +02:00
|
|
|
|
"✅ No pending reboot."
|
2022-10-04 16:09:27 +02:00
|
|
|
|
}
|
|
|
|
|
exit 0 # success
|