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.

Steps

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 "

 

#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 the administrator"

        }

    }

    $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;

} 

 

References

For more Detail