You're likely accustomed to rebooting a Windows computer, and the PowerShell pending reboot module can make that process easier.
Windows requires a reboot to successfully finish operations, such as updating drivers and installing patches, third-party software and Windows features. A restart gives Windows the opportunity to change or remove files without causing instability.
You can check if Windows has a pending reboot with the PowerShell pending reboot module, created by Brian Wilhite, a Microsoft premier field engineer.
Get started with the pending reboot module
Use the PowerShell Gallery to install the PowerShell pending reboot module.
PS C:\> Install-Module PendingReboot
The module will be loaded into the current PowerShell session with the cmdlet Test-PendingReboot. While looking at the code inside of the PowerShell pending reboot cmdlet, you can see where the cmdlet checks for a pending reboot in the Windows registry. These locations map to component-based servicing (CBS), Windows Update, an Active Directory (AD) join, and the System Center Configuration Manager software development kit (SCCM SDK).
The CBS stack was introduced with Windows Vista and encompasses various tools to service Windows while keeping the OS stable. CBS has several different levels for servicing. The first is for Windows Update, programs and features, and MSI. The second level is the trusted installer, which runs in Task Manager during certain installations. The last level is for kernel transactions to Windows.
PowerShell experts that choose to write their own test code rather than use the available Test-PendingReboot cmdlet detailed here can also look for True or False reboot conditionals within three common Windows registry entries:
- The RebootPending value at HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing
- The RebootRequired value at HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update
- The PendingFileRenameOperations value at HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager
How to use Test-PendingReboot
By default, when running the Test-PendingReboot cmdlet on the local system, it will return two properties: ComputerName and IsRebootPending.
Note that SCCM doesn't manage the system, so the cmdlet can't find the SCCM SDK in the registry. If you want to skip the cmdlet from checking, you can use the parameter SkipConfigurationManagerClientCheck.
You can find more information from the cmdlet than pending reboots. If you run the cmdlet with the -Detailed parameter, it will give the status on all of the areas in the registry it checks.
For example, if you install Mozilla Firefox, Thunderbird and Acrobat DC, each will have a pending file renaming operation. The PendingFileRenameOperationsValue property can have multiple values, which you can see by piping Test-PendingReboot to Foreach-Object. The next reboot will rename the files.
In addition to checking pending reboots locally, you can specify the -ComputerName parameter, which will use Invoke-WMIMethod to remotely connect and check the same registry values.
Use Get-ADComputer from the AD module to retrieve computers to query.
In the above command, first query AD for any system under the organizational unit servers and then query them with Test-PendingReboot.