Get-PendingReboot - Query Computer(s) For Pending Reboot State

This function gets the pending reboot status on a local or remote computer. Now supports SCCM 2012 Clients.

 
 
 
 
 
4.5 Star
(87)
100,893 times
Add to favorites
Windows Update
6/20/2016
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Powershell returns nothing
    3 Posts | Last post May 17, 2018
    • I have test powershell and script does run. Currently, it returns nothing. No error. No output in $error. 
      
      I have file text file and system name to test with both return nothing.
      
    • I had the same issue, the posts from Brian C. White and Markus E. Kugler helped to get mine to work in Server 2008
    • I had the same issue, could someone advice how to run!? when try to run error showing not recognized command
      
      PS C:\> Get-PendingReboot -ComputerName vnhcmm0dhcp02
      Get-PendingReboot : The term 'Get-PendingReboot' is not recognized as the name of a cmdlet, function, script file, or
      operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
      again.
      At line:1 char:1
      + Get-PendingReboot -ComputerName vnhcmm0dhcp02
      + ~~~~~~~~~~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (Get-PendingReboot:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
  • wrong output
    2 Posts | Last post May 13, 2018
    • Hi Brian,
      
      Thank you very much for the great script! I added the "last reboot"-feature and the mail-feature (seen here in q&a).
      
      the script is running daily as a scheduled task from my sccm server.
      
      I run in one issue:
      
      the script returns me tons of servers that seem to wait for a reboot but they don't.
      
      when I check the server directly it shows me that the server is not pending for reboot:
      
      PS C:\SCRIPT> get-pendingreboot -computername cert01
      
      Computer           : CERT01
      LastReboot         : 29.12.2017 12:04:28
      CBServicing        : False
      WindowsUpdate      : False
      CCMClientSDK       : False
      PendComputerRename : False
      PendFileRename     : False
      PendFileRenVal     : 
      RebootPending      : False
      
      
      I think it is because of the "PendFileRenVal". So I removed the PendFileRename and PendFileRenVal from the script...
      
      
      	    ## Creating Custom PSObject and Select-Object Splat
      	    $SelectSplat = @{
      	        Property=(
      	            'Computer',
                      'LastReboot',
      	            'CBServicing',
      	            'WindowsUpdate',
      	            'CCMClientSDK',
      	            'PendComputerRename',
      	            'RebootPending'
      	        )}
      	    New-Object -TypeName PSObject -Property @{
      	        Computer=$WMI_OS.CSName
                  LastReboot=$lastreboot.lastbootuptime
      	        CBServicing=$CBSRebootPend
      	        WindowsUpdate=$WUAURebootReq
      	        CCMClientSDK=$SCCM
      	        PendComputerRename=$CompPendRen
      	        RebootPending=($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM)
      	    } | Select-Object @SelectSplat
      
      
      ...but it does not change anything
      
      can you help me?
      
      Thank you very much!
      
      Best regards
      Markus
      
    • My understanding is that though the server is not showing that it requires a reboot, there is a file waiting to be renamed, which can only happen after a reboot. I inferred this after reading this post: 
      https://blogs.technet.microsoft.com/brad_rutkowski/2007/06/27/are-there-pending-operations-waiting-for-a-reboot/
  • downloading this script result in a blank 0KB file
    1 Posts | Last post May 09, 2018
    • downloading this script result in a blank 0KB file
      
      Is there an error perhaps?
  • added HTML-Mail and AD-Server-query
    1 Posts | Last post January 10, 2018
    • Hi *
      
      this is how I use it. Thanks to McNunzio and IT Billing for inspiration:
      
      [begin script]
      
      
      Import-Module .\Get-PendingReboot.ps1
      Import-Module ActiveDirectory
      
      $computers = Get-ADComputer -Filter * -Properties operatingsystem |Where operatingsystem -match 'server' |where {$_.enabled -ne $false} |Sort-Object name
      
      $Reboots = Get-PendingReboot -Computer $computers.Name |where {$_.RebootPending -eq $true}|select computer, LastReboot, CBServicing, WindowsUpdate, CCMClientSDK |ConvertTo-Html -Head $style
      
      
      
      #########################################
      #E-mail Reboot Report To IT-Deptartment #
      #########################################
      $style = "<style>BODY{font-family: Verdana; font-size: 10pt;}"
      $style = $style + "TABLE{border: 1px solid black; border-collapse: collapse;}"
      $style = $style + "TH{border: 1px solid black; background: #dddddd; padding: 5px; }"
      $style = $style + "TD{border: 1px solid black; padding: 5px; }"
      $style = $style + "</style>"
      
      $smtpServer = "my-mailserver-fqdn"
      $smtpFrom = "RebootReport@company.com"
      $smtpTo = "it-dept@company.com"
      $messageSubject = "[info] Server pending reboots"
      
      $message = New-Object System.Net.Mail.MailMessage $smtpFrom, $smtpTo
      $message.Subject = $messageSubject
      $message.IsBodyHtml = $true
      $message.Body =@"
      <p style="$style">Servers waiting for a Reboot:</p>
      
      $Reboots
      "@
      
      $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
      $smtp.Send($message)
      
      [end script]
  • Condensing the report to only show true values
    2 Posts | Last post December 29, 2017
    • Hi Brian, 
      
      Great script! I've put this into a scheduled task that runs and e-mails a report out to some admins regarding the pending reboots for any servers in the environment. I was just wondering if we can make it so it only shows the values that are listed as True so i can shorten the e-mail that goes out to only include the ones they need to see?
      
      Here's what i am using:
      
      $smtpServer = "MAILSERVER"
      $smtpFrom = "RebootReport@domain.com"
      $smtpTo = "AdminsWhoCare@domain.com"
      
      Import-Module .\Get-PendingReboot.ps1
      $Reboots = Get-PendingReboot -ComputerName (Get-Content C:\Scripts\ServerList.txt) | Format-Table -AutoSize | Out-String
      
      
      
      
      #############################################
      #E-mail Reboot Report to Admins
      #############################################
      $messageSubject = "Currently Pending Server Reboots"
      $messageBody = @"
      $Reboots
      
      "@
      
      $smtp = New-Object Net.Mail.SmtpClient($smtpServer)
      $smtp.Send($smtpFrom,$smtpTo,$messageSubject,$messageBody)
    • Hi MC Nunzio,
      thanks for sharing your mail report settings.
      do you know how i can achieve that the output-tabel in the mail is also formatted like on console output?
      thanks
      Markus
  • RebootPending
    1 Posts | Last post December 28, 2017
    • Hi Brian 
      
      I would like to thank you for your good effort .
      
      I run the Query with success but I got the following Columns , the RebootPending colums value is true for some servers which dont require reboot or at least not shown in SRV manager dashboard  ! .
      
      opposite WindowsUpdate all true require restart .
      
      could you please explain the reason .
       
      Computer	CBServicing	WindowsUpdate	CCMClientSDK	PendComputerRename	PendFileRename	PendFileRenVal	RebootPending
      
      
      Best regards 
      Sid 
  • For workgroup join/leave how we will detect?
    1 Posts | Last post November 08, 2017
    • this script doesn't work for workgroup join/leave any suggestion how we can detect this? 
  • Can you add the -Credential option?
    3 Posts | Last post November 07, 2017
    • Brian -- would it be possible to add the ability to use the standard -Credential parameter, such that I could issue a "Get-PendingReboot servername -Credential (Get-Credential)" command for servers that won't accept my standard credential?  In our environment, that would be workgroup servers, domain controllers, etc.
    • modify function like that:
      param(
      	[Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
      	[Alias("CN","Computer")]
      	[String[]]$ComputerName="$env:COMPUTERNAME",
          [Parameter(Position=1,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
          [Alias("credential")]
       	[Management.Automation.PSCredential]$Credentials=$env:Credentials,
      	[String]$ErrorLog    
      	)
      .
      .
      $WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -Property BuildNumber, CSName -ComputerName $Computer -Credential $credentials -ErrorAction Stop
      
      $WMI_Reg = Get-WmiObject -List -Namespace "root\default" -ComputerName $Computer -Credential $credentials| Where-Object {$_.Name -eq "StdRegProv"}
      
      
    • Thank you povreshellcoder, worked perfectly! :)
  • Parameters not wprking
    5 Posts | Last post November 02, 2017
    • Hi, I can run this locally and it reports correctly. I however cannot add the -computername parameter. After typing the script and beginning to type "-comp" and then attempting to tab over it will not even bring up the -computername parameter.
      
      Even if I use the following command:
      
      $Servers = Get-Content C:\servers.txt
      .\Get-PendingReboot -ComputerName $Servers | Export-Csv C:\PendingRebootReport.csv -NoTypeInformation
      
      The output will only be the local system. Its almost like something was updated that will not let me call up the -computername parameter.
      
      Any thoughts?
    • Wow this seems to cool...
    • Good afternoon, did you solve the fault with the parameter ComputerName?
    • Hi Alan, the script is designed to be dot sourced, meaning it will need to be loaded in your current session by typing a period plus a space in front of the path to the script, i.e.:
      
      PS C:\> . C:\Scripts\Get-PendingReboot.ps1
      PS C:\> Get-PendingReboot -ComputerName <ComputerName>
    • One way around the dot-sourcing issue is to add the function to a module and import it.  I have several modules I import in my profile, and I added this script to the ServerAdmin module that gets imported every time I open PS.
      
  • Multiple Updates and reboot reporting
    1 Posts | Last post August 04, 2017
    • Morning! lol 
      
      Hey Brian, Is there a way via Reg/WMI that you can query if a SCCM update push is complete before reporting that a reboot is required in the event of multiple updates being installed that could require a reboot? Im researching it but didnt know if you knew off the top of your head. I didnt want to run a script and run into the issue of it detecting a reboot is needed for an update that was part of the push while other updates were still being installed as part of that push.
1 - 10 of 67 Items