Check if reboot is pending (windows 10 and 11)

I need to check if there is a pending reboot before installing my software. If there is a pending reboot, stop the installation, otherwise continue the installation. Does anyone know how to do this in deploy-application.ps1?

Here is piece of what I use do deal with pending reboots:

$PendingRebootInfo = Get-PendingReboot
If ($PendingRebootInfo.IsSystemRebootPending) {
	Write-log "Pending Reboots found"
	If ($runningTaskSequence) {
		Write-log "INSIDE TASK SEQUENCE: Ignoring pending reboots" -Severity 2

	} Else {
		Write-log "NOT Running inside a task sequence. " -Severity 2

	}		
} Else {
	Write-Log "No pending reboot detected. Continuing install..." 
}
1 Like

I also have this extra function in case there are some other pending reboot factors.
I did not find (I know it’s my fault) the tags for sharing code.

function Test-PendingReboot
{
    if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
    if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
    if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
    if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\ControlSet001\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
    if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\ControlSet002\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }

    try 
    { 
    $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
    $status = $util.DetermineIfRebootPending()
    if(($status -ne $null) -and $status.RebootPending)
    {
        return $true
    }
    }
    catch
    {
    }

 return $false
}

Some great tips in this one, I have a couple of apps/vendors where the setup.exe or MSI will not run if it detects a pending reboot.

I had a similar issue recently with a script and found a way to handle it. In your deploy-application.ps1, you can check for a pending reboot by querying the registry or system status. For instance, you can use PowerShell commands to check specific registry keys or use the Get-WmiObject cmdlet to see if a reboot is pending.

A handy resource I found was operatingsystems.info—they have some useful tips on handling system states and installations. If you’re interested, their guide might offer more specific examples and solutions. It helped me get my scripts sorted out without running into issues.