How to upload and download files with PowerShell FTP script Microsoft Windows PowerShell DSC (Desired State Configuration)

How to test the PowerShell pending reboot module

Learn how to check if your machines have pending reboots with a simple PowerShell module to ensure changes to files do not cause stability issues.

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.

Test-PendingReboot cmdlet
How to use the Test-PendingReboot cmdlet.

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.

Test-PendingReboot cmdlet with -Detailed parameter
The -Detailed parameter 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.

Test-PendingReboot to Foreach-Object
Pipe Test-PendingReboot to Foreach-Object to show PendingFileRenameOperationsValue property's multiple values.

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.

Get-ADComputer from the AD module
Use Get-ADComputer from the Active Directory 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.

Next Steps

4 PowerShell modules every IT pro should know

What's new with PowerShell error handling?

Build a PowerShell logging function for troubleshooting

Dig Deeper on Microsoft messaging and collaboration

Cloud Computing
Enterprise Desktop
Virtual Desktop