2024-11-08 12:38:20 +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
|
|
|
|
|
|
|
|
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-05-19 10:25:56 +02:00
|
|
|
✅ No pending 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 {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reply = "✅ No pending reboot"
|
2023-05-26 12:20:18 +02:00
|
|
|
if ($IsLinux) {
|
|
|
|
if (Test-Path "/var/run/reboot-required") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reply = "⚠️ Pending reboot (found: /var/run/reboot-required)"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
} else {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason = ""
|
2023-05-26 12:20:18 +02:00
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired") {
|
2024-11-08 12:35:11 +01: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") {
|
2024-11-08 12:35:11 +01: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") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason += ", ...\Component Based Servicing\RebootPending"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts") {
|
2024-11-08 12:35:11 +01: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") {
|
2024-11-08 12:35:11 +01: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") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason += ", '...\CurrentVersion\Component Based Servicing' with 'PackagesPending'"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Value "PendingFileRenameOperations2") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason += ", '...\CurrentControlSet\Control\Session Manager' with 'PendingFileRenameOperations2'"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" -Value "DVDRebootSignal") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason += ", '...\Windows\CurrentVersion\RunOnce' with 'DVDRebootSignal'"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "JoinDomain") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason += ", '...\CurrentControlSet\Services\Netlogon' with 'JoinDomain'"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
|
|
|
if (Test-RegistryValue -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon" -Value "AvoidSpnSet") {
|
2024-11-08 12:35:11 +01:00
|
|
|
$reason += ", '...\CurrentControlSet\Services\Netlogon' with 'AvoidSpnSet'"
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
2024-11-08 12:35:11 +01:00
|
|
|
if ($reason -ne "") {
|
|
|
|
$reply = "⚠️ Pending reboot (registry got $($reason.substring(2)))"
|
2023-07-29 09:45:37 +02:00
|
|
|
}
|
2023-05-26 12:20:18 +02:00
|
|
|
}
|
2024-11-08 12:35:11 +01:00
|
|
|
Write-Host $reply
|
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-11-20 11:52:20 +01:00
|
|
|
*(generated by convert-ps2md.ps1 as of 11/20/2024 11:51:51)*
|