2024-01-25 13:37:12 +01:00
|
|
|
Script: *check-pending-reboot.ps1*
|
|
|
|
========================
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
check-pending-reboot.ps1
|
2022-11-17 19:46:02 +01:00
|
|
|
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Parameters
|
|
|
|
----------
|
2022-11-17 19:46:02 +01:00
|
|
|
```powershell
|
|
|
|
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
2023-07-29 10:04:38 +02:00
|
|
|
Script Content
|
|
|
|
--------------
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Check for pending reboots
|
|
|
|
.DESCRIPTION
|
2023-07-29 09:45:37 +02:00
|
|
|
This PowerShell script queries pending operating system reboots and prints it.
|
2022-11-17 20:02:26 +01:00
|
|
|
.EXAMPLE
|
|
|
|
./check-pending-reboot.ps1
|
2024-01-25 13:31:10 +01:00
|
|
|
✅ No pending system reboot
|
2022-11-17 20:02:26 +01:00
|
|
|
.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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-26 12:20:18 +02:00
|
|
|
try {
|
|
|
|
$Reason = ""
|
|
|
|
if ($IsLinux) {
|
|
|
|
if (Test-Path "/var/run/reboot-required") {
|
2023-07-29 09:45:37 +02:00
|
|
|
$Reason = "found: /var/run/reboot-required"
|
|
|
|
Write-Host "⚠️ Pending reboot ($Reason)"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
|
2023-07-29 09:45:37 +02:00
|
|
|
$Reason += ", ...\Auto Update\RebootRequired"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting") {
|
2023-07-29 09:45:37 +02:00
|
|
|
$Reason += ", ...\Auto Update\PostRebootReporting"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending") {
|
2023-07-29 09:45:37 +02:00
|
|
|
$Reason += ", ...\Component Based Servicing\RebootPending"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") {
|
2023-07-29 09:45:37 +02:00
|
|
|
$Reason += ", ...\ServerManager\CurrentRebootAttempts"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "RebootInProgress") {
|
2023-07-29 09:45:37 +02:00
|
|
|
$Reason += ", ...\CurrentVersion\Component Based Servicing with 'RebootInProgress'"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing" -Value "PackagesPending") {
|
|
|
|
$Reason += ", '...\CurrentVersion\Component Based Servicing' with 'PackagesPending'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") {
|
|
|
|
$Reason += ", '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations2'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") {
|
|
|
|
$Reason += ", '...\Windows\CurrentVersion\RunOnce' with 'DVDRebootSignal'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") {
|
|
|
|
$Reason += ", '...\CurrentControlSet\Services\Netlogon' with 'JoinDomain'"
|
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") {
|
|
|
|
$Reason += ", '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'"
|
|
|
|
}
|
2023-07-29 09:45:37 +02:00
|
|
|
if ($Reason -ne "") {
|
|
|
|
Write-Host "⚠️ Pending reboot (registry contains $($Reason.substring(2)))"
|
|
|
|
}
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
2023-07-29 09:45:37 +02:00
|
|
|
if ($Reason -eq "") {
|
2024-01-25 13:31:10 +01:00
|
|
|
Write-Host "✅ No pending system reboot"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
2022-11-17 20:02:26 +01:00
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2024-01-25 13:58:49 +01:00
|
|
|
*(generated by convert-ps2md.ps1 using the comment-based help of check-pending-reboot.ps1 as of 01/25/2024 13:58:36)*
|