Check if Reboot is Required on multiple server - using Powershell GUI based tool

Check if Reboot is Required on multiple server - using Powershell GUI based tool


This is a powershell script that will help you to find if a reboot is required on a server or a multiple server.

Note: This script will not reboot any of the server. It will just give you true/false value if the reboot is pending or not.

Lets Start:

Whenever you check for updates, after updating the patches it generates registry RebootRequired.
This information is stored at HKeyLocalMachine of the registry.

Below are several paths where you can find it --

To open registry --> press windows+R then type regedit hit enter..

"HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\"

"HKLM\SYSTEM\CurrentControlSet\Control\Session Manager"

"HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired "

 Script 1:

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 }

try { 

$util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"

$status = $util.DetermineIfRebootPending()

if(($status -ne $null) -and $status.RebootPending){

return $true

}

}catch{}



return $false

}
Script 2:
#specify text file path that contains list of server

$d = get-content "path to your text file"
  $RebootRequired = " "
  $RebootNotRequired = " "
  $badservername = " "
  foreach ($t in $d)
  {
   try
   {
    $baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $t)
    $key = $baseKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
    $subkeys = $key.GetSubKeyNames()
    $key.Close()
    $baseKey.Close()
    If ($subkeys | Where { $_ -eq "RebootPending" })
    {
     
     $RebootRequired = $RebootRequired + $t + "`r`n "
    }
    Else
    {
    
     $RebootNotRequired = $RebootNotRequired + $t + "`r`n"
    }
   }
   catch
   {
    $badservername = $badservername + $t + "`r`n"
    Write-Host "Non pinging servers are ignored. For other exceptions please contact Nishant" 
   }
   }
  $pathRebootRequired = "$([Environment]::GetFolderPath("Desktop"))\RebootRequired.txt";
  $pathRebootNotRequired = "$([Environment]::GetFolderPath("Desktop"))\RebootNotRequired.txt";
  $pathbadservername = "$([Environment]::GetFolderPath("Desktop"))\badservername.txt";
  "Reboot Required for below servers: `r`n$RebootRequired " | fl > $pathRebootRequired; 
  notepad $pathRebootRequired;
  "Reboot NOT Required for below servers: `r`n$RebootNotRequired" | fl > $pathRebootNotRequired; 

  notepad $pathRebootNotRequired;
  "Below are list of bad servername, please try to check their ping response: `r`n$badservername" | fl > 

   $pathbadservername; 

  notepad $pathbadservername;
  
 }


*****************************************************************************

Screenshot:

How to Use?

1. Double click on the file, it will launch the GUI. 
2.Enter the hostname in the text area provided. You can enter multiple hostname at once.
Note: Write one hostname per line. Dont write multiple hostname in the same line.
3. Once done click on Initialise, to generate result.
4. This will produce 3 text file. 
"RebootRequired.txt" all hosts that requires reboot will appear here
"RebootNotRequired.txt" all hosts that does not require a reboot will appear here
"badservername.txt" servers that are not reachable appear here
All these text file will be saved at your desktop.

Download:

Thanks Guys,
Comment down below if you have any query :)
Previous
Next Post »
0 Comments