From 1e3265b02b8b0c304ef8210c715633ba6e051dcb Mon Sep 17 00:00:00 2001
From: Markus Fleschutz <markus.fleschutz@gmail.com>
Date: Fri, 13 Jan 2023 17:59:15 +0100
Subject: [PATCH] Update check-pending-reboot.ps1

---
 Scripts/check-pending-reboot.ps1 | 70 +++++++++++++++++---------------
 1 file changed, 38 insertions(+), 32 deletions(-)

diff --git a/Scripts/check-pending-reboot.ps1 b/Scripts/check-pending-reboot.ps1
index 0439fbe8..f0b4825e 100644
--- a/Scripts/check-pending-reboot.ps1
+++ b/Scripts/check-pending-reboot.ps1
@@ -22,38 +22,44 @@ function Test-RegistryValue { param([parameter(Mandatory=$true)][ValidateNotNull
 
 try {
 	$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 ($IsLinux) {
+		if (Test-Path "/var/run/reboot-required") {
+			$Reason = "found /var/run/reboot-required"
+		}
+	} else {
+		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 "") {
 		Write-Host "⚠️ Pending reboot ($($Reason.substring(2)))"