Also working on a powershell script. 1 of many referenced used: https://adamtheautomator.com/pending-reboot-registry-windows/
Here is what I have so far. If anyone wants to test and give feedback and update it, I would appreciate it. Not sure I need to check for file renames since those seem to be running true alot. Could be an error in my code. Also, Reboot for pending updates is marking as true although when I check windows updates it doesnt say any are pending or applied. So most likely an error in my code as well.
function Test-RegistryKey {
[OutputType(‘bool’)]
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Key
)
$ErrorActionPreference = ‘Stop’
if (Get-Item -Path $Key -ErrorAction Ignore) {
$true
}else {
$false }
}
function Test-RegistryValue {
[OutputType(‘bool’)]
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Key,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Value
)
$ErrorActionPreference = ‘Stop’
if (Get-ItemProperty -Path $Key -Name $Value -ErrorAction Ignore) {
$true
}else {
$false }
}
function Test-RegistryValueNotNull {
[OutputType(‘bool’)]
[CmdletBinding()]
param
(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Key,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string]$Value
)
$ErrorActionPreference = ‘Stop’
if (($regVal = Get-ItemProperty -Path $Key -Name $Value -ErrorAction Ignore) -and $regVal.($Value)) {
$true
}else {
$false }
}
write ‘Component Reboot Pending’
Test-RegistryKey -Key ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending’
Write ‘Component Reboot in Progress’
Test-RegistryKey -Key ‘HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress’
Write ‘Windows Autoupdate Reboot Required’
Test-RegistryKey -Key ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired’
write ‘Component Package Reboot Pending’
Test-RegistryKey -Key ‘HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending’
write ‘Windows Autoupdate post reboot’
Test-RegistryKey -Key ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting’
write ‘Pending file rename 1’
Test-RegistryValueNotNull -Key ‘HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager’ -Value ‘PendingFileRenameOperations’
write ‘Pending file rename 2’
Test-RegistryValueNotNull -Key ‘HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager’ -Value ‘PendingFileRenameOperations2’
write ‘Runonce Reboot required’
Test-RegistryValue -Key ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce’ -Value ‘DVDRebootSignal’
Write ‘Reboot Attempts’
Test-RegistryKey -Key ‘HKLM:\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts’
write ‘Reboot to join domain’
Test-RegistryValue -Key ‘HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon’ -Value ‘JoinDomain’
write ‘Reboot avoice spn set’
Test-RegistryValue -Key ‘HKLM:\SYSTEM\CurrentControlSet\Services\Netlogon’ -Value ‘AvoidSpnSet’
write ‘Reboot to change computer name’
(Get-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName’).ComputerName -ne
(Get-ItemProperty -Path ‘HKLM:\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName’).ComputerName
write ‘Reboot for pending updates’
if (Get-ChildItem -Path ‘HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending’) {
$true
}else {
$false }
write ‘Windows update reboot now’
if (Get-ItemProperty -Path ‘HKLM:\SOFTWARE\Microsoft\Updates’ -Name ‘UpdateExeVolatile’ | Select-Object -ExpandProperty ‘UpdateExeVolatile’ -ExcludeProperty ‘0’) {
$true
}else {
$false }