Checking For Pending Restart

Pending reboot can be caused by variety of reasons, not just the ones that are detailed in other answers. Try PendingReboot module, which incorporates various tests into a single cmdlet: # Install Install-Module -Name PendingReboot # Run Test-PendingReboot -Detailed. A pending reboot is defined in many places. Scroll right to see the values and conditions. A Windows computer is pending a reboot if any of the conditions in this table are true. If you have the Microsoft System Center Configuration Manager (SCCM) client installed, you may also see these methods in WMI.

If you’re trying to determine which of your servers require reboots, you’ll love this PowerShell script to check the status.

It turns out that a simple way to identify servers that are pending reboot is to check the registry.

This information is stored in the HKeyLocalMachine hive of the registry.

[convertkit form=949492]

PowerShell is perfect for working with the registry.

Registry is one of the built-in PowerShell providers!

Checking For Pending Restart Windows 10

There’s even already a PSDrive connected to that registry hive!

You can’t ask for anything more… except to maybe be able to map a new PSDrive to a different part of the Registry — which is ALSO super easy to do!

You can browse around the registryjust like you do with the filesystem.

For

Wow! Super easy, right?

Now you just need to know where the “pending reboot” location is. There are a couple of places to check.

RestartRestart
  • HKLMSOFTWAREMicrosoftWindowsCurrentVersionWindowsUpdateAuto UpdateRebootRequired

Is where patches installed through automatic updates register the need to reboot.

  • HKLMSOFTWAREMicrosoftWindowsCurrentVersionComponent Based ServicingRebootPending

Is another place where pending reboots can be identified.

  • HKLMSYSTEMCurrentControlSetControlSession Manager

Is yet another. Finally, there is Configuration Manager which, if present, can be queried via WMI.

I found a function that I really like to check all four locations.

I’ll need to wrap it up with some parameters to check remote computers, but in general it was a great start.

I’ve adapted the function to return $true on the first condition that satisfies, since I only care about whether the computer is pending a reboot, and not where the source of the reboot is coming from.

As a DBA we make every effort to avoid bringing systems off line, however there are times where that is exactly what needs to happen. From a Windows and SQL Server perspective there are a number of changes that require a reboot. These reasons range from the application of Windows updates, the changing of Windows policies and changes to SQL Server settings. Over the years there have been a number of times where I have connected to a server and found a message stating that there is a pending reboot. When changes are made, of course we want the changes to take effect as soon as possible. In some cases a change will not take effect until a reboot happens. In order to determine if there is a pending reboot, we need to look at a number of places, including both Windows and SQL Server.

Starting with Windows, there are some changes that require a reboot, including that application of Windows updates. Checking for a pending reboot for Windows can be done using one of the newest friends of a DBA, Powershell. The information that needs to be queried is in the registry.

This is the popup that I have seen a number of times showing that there is a pending update. What makes this the less than ideal option is that I need to logon to the server.

Brian Wilhite has a very nice PowerShell module that you can use to check for pending reboots in Windows. It can be found on GitHub here. It can also be found on PowerShellGallery.com here. You can also download the ps1 file here.

On August 20, 2018 he stated on Microsoft’s Script Center web site that he is no longer making updates to this on the Script Center site, you will need to get it from GitHub instead, link is above. According to the Script Center site here are the versions of the OS it has been tested on. I have tested it on Windows 10 and it appears to work just fine.

The script below will install the module and complete the check.

# Install

# Run
Test-PendingReboot -Detailed -ComputerName localhost
In order to run this script, you must run the Powershell application as Administrator. If you do not, you will see this error.
Below are the results of running the PendingReboot PowerShell script. By adding the -Detailed switch you will see more information about what might have caused the need for the restart. In addition, you can add the -ComputerName switch to check a remote computer.
What I like about this is that it allows me to test a remote computer. Just as a precautionary measure, make sure to throughout research and exercise the appropriate caution prior to running any code obtained on the internet on production servers.
Of course knowing if there is a pending reboot in Windows is important, however there are a number of SQL Server settings that will also cause a need for a restart of the SQL Server service in order to take effect. The above powershell script will not detect this. There are a few ways using SQL Server Management Studio that can tell us if the service needs to be restarted.
The first method is to look at the settings of the SQL Server. At the bottom you will see “Configured Value” and “Running Value”. If you look at the images below, you can see that the Default index fill factor is different. The configured value is 0, while the running value is 85. This is a sign that the SQL Server service needs to be restarted.

The drawback of this type of check is that I need to manually go to each setting option and do a compare. Luckily, Microsoft has added a view for us to use to programmatically check this. The view is sys.configurations. There are a number of columns that are important for what we are looking for. Below I have listed the columns that are important for the purpose of this post. Of course there are more columns that these.

Clear Pending Restart Windows 10

Is_dynamic is the column that will tell us if a restart is needed if that value of the setting is changed. If this is true, a restart of the service is not needed if the value is changed.

is_advanced identifies if it is an advanced option

Checking For Pending Restart

value_in_use is the column that will tells us the Running value How to install bamini tamil font in windows.

value will identify that configured value

When looking at this, if Value_in_use and value are different, then a service restart is needed. In this case, the fill factor(%) is different. The running value is use is 85% while the configured value is 0.

Check For Pending Restart Powershell

This is the code used to get the above result set.

SELECT name
, is_dynamic
, is_advanced
, value_in_use
, value
FROMsys.configurations
WHERE is_dynamic = 0

In order to determine if a restart is needed, we need to add more to the WHERE clause. We just need to do a simple comparison of the value_in_use and the value columns. Of course we are also only looking at the settings that is_dynamic is set to FALSE or 0. If this query below returns any rows, a restart of the service is needed in order to have it take effect.

SELECT name
, is_dynamic
, is_advanced
, value_in_use
, value
FROMsys.configurations
WHERE is_dynamic = 0
AND value <> value_in_use
IF@@ROWCOUNT >= 1
BEGIN
SELECT‘Restart is needed’AS‘Restart Needed?’
END
ELSE
BEGIN
SELECT‘NO restart is needed’AS ‘Restart Needed?’
END
Hopefully you will find this information useful.
Thank you for visiting my blog.