2022-12-04 10:40:18 +01:00
|
|
|
## The *check-pending-reboot.ps1* Script
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
check-pending-reboot.ps1
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
```powershell
|
|
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
## Source Code
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01: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)
|
|
|
|
try {
|
|
|
|
Get-ItemProperty -Path $Path -Name $Value -EA Stop
|
|
|
|
return $true
|
|
|
|
} catch {
|
|
|
|
return $false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$Reason = ""
|
|
|
|
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
|
|
|
|
$Reason += ", found registry entry '...\WindowsUpdate\Auto Update\RebootRequired'"
|
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") {
|
|
|
|
$Reason += ", found registry entry '...\WindowsUpdate\Auto Update\PostRebootReporting'"
|
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") {
|
|
|
|
$Reason += ", found registry entry '...\Component Based Servicing\RebootPending'"
|
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") {
|
|
|
|
$Reason += ", found registry entry '...\ServerManager\CurrentRebootAttempts'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") {
|
|
|
|
$Reason += ", found registry entry '...\CurrentVersion\Component Based Servicing' with 'RebootInProgress'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") {
|
|
|
|
$Reason += ", found registry entry '...\CurrentVersion\Component Based Servicing' with 'PackagesPending'"
|
|
|
|
}
|
|
|
|
#if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations") {
|
|
|
|
# $Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations'"
|
|
|
|
#}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") {
|
|
|
|
$Reason += ", found registry entry '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations2'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") {
|
|
|
|
$Reason += ", found registry entry '...\Windows\CurrentVersion\RunOnce' with 'DVDRebootSignal'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") {
|
|
|
|
$Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'JoinDomain'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") {
|
|
|
|
$Reason += ", found registry entry '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'"
|
|
|
|
}
|
|
|
|
if ($Reason -ne "") {
|
2022-12-04 10:40:18 +01:00
|
|
|
"⚠️ Pending reboot ($($Reason.substring(2)))"
|
2022-11-17 20:02:26 +01:00
|
|
|
} else {
|
2022-12-04 10:40:18 +01:00
|
|
|
"✅ No pending reboot"
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
|
|
|
exit 0 # success
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2022-11-17 19:46:02 +01:00
|
|
|
*Generated by convert-ps2md.ps1 using the comment-based help of check-pending-reboot.ps1*
|