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
(99)
156,219 times
Add to favorites
Windows Update
8/30/2018
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Script shows nothing in output
    1 Posts | Last post October 10, 2019
    • Hi all,
      unfortunately this scripts shows nothing in output.
      I tried some commands
      Get-PendingReboot -ComputerName (Get-Content C:\computers.txt)
      Get-PendingReboot -ComputerName computerA
      Get-PendingReboot
      
      No of this commands show any output. Also no error!
      Best regards
      Birdal
  • Run in Task Scheduler job
    1 Posts | Last post March 20, 2019
    • i got it working running in task scheduler job. 
      
      1) create new task schedule job | in the actions tab | program/script | use this "powershell Invoke-Command{cd "C:\Admin\Scripts\PendingReboot";./Report_Reboot_Exchange.ps1}"
      
      2) save the as .ps1
      
      ---------------------------------------------
      . .\Get-PendingReboot.ps1
      
      Get-PendingReboot -ComputerName (Get-Content C:\Temp\Servername.txt) | select Computer, WindowsUpdate, RebootPending | 
      export-csv "C:\TEMP\Servername_$((Get-Date).ToString('MM-dd-yyyy')).csv" -NoTypeInformation
      
      
      $file = "C:\TEMP\Servername_$((Get-Date).ToString('MM-dd-yyyy')).csv"
      $smtpServer = "relay.abc.com"
      $att = new-object Net.Mail.Attachment($file)
      $msg = new-object Net.Mail.MailMessage
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
      $msg.From = "user1@abc.com"
      $msg.To.Add("user2@abc.com")
      $msg.Subject = "Pending Exchange Server Reboot Report Status"
      $msg.Body = "Attached is pending server reboot" + (import-csv C:\temp\Servername_$((Get-Date).ToString('MM-dd-yyyy')).csv | out-string)
      $msg.Attachments.Add($att)
      $smtp.Send($msg)
      $att.Dispose()
      -----------------------------------------
  • script to run in task scheduler
    2 Posts | Last post March 14, 2019
    • I'm trying to write a script so I can run it in task scheduler. 
      
      When I tested with this “powershell -file "C:\Admin\Scripts\PendingReboot\Report_Reboot_Exchange.ps1" I get the error message in below.. is my path incorrect syntax ?
      
      this is in the txt file .ps1
      -------------------------------------------------------------------------------
      Import-Module.C:\temp\Get-PendingReboot.ps1
      
      
      Get-PendingReboot -ComputerName (Get-Content C:\temp\ExchangeSRV.txt) | select Computer, WindowsUpdate, RebootPending | export-csv C:\temp\Exchange_Server_Pending_Reboot.csv -NoTypeInformation
      
      
      $file = "C:\temp\Exchange_Server_Pending_Reboot.csv"
      $smtpServer = "relayny.debevoise.net"
      $att = new-object Net.Mail.Attachment($file)
      $msg = new-object Net.Mail.MailMessage
      $smtp = new-object Net.Mail.SmtpClient($smtpServer)
      $msg.From = "user@abc.com"
      $msg.To.Add("user1@abc.com")
      $msg.Subject = "Pending Exchange Server Reboot Report Status"
      $msg.Body = "Attached is pending server reboot" + (import-csv C:\ADMIN\Scripts\PendingReboot\Exchange_Server_Pending_Reboot.csv | out-string)
      $msg.Attachments.Add($att)
      $smtp.Send($msg)
      $att.Dispose()
      -------------------------------------------------------------------------------
      
      
      error message 
      
      Import-Module.C:\Admin\Scripts\PendingReboot\Get-PendingReboot.ps1 : The term
      'Import-Module.C:\Admin\Scripts\PendingReboot\Get-PendingReboot.ps1' 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.
      
    • I'm trying to run this in task scheduler.. how do I call this ". .\Get-PendingReboot.ps1" in ISE windows powershall ?
      
      this file is in c:\temp\script directory 
      
      I tried with something like this and still didn't work 
      
      ". .c:\temp\script\Get-PendingReboot.ps1"
      
      
      ----------------------------------------------------------------------------
      powershell.exe -command  ". .C:\temp\Scripts\Get-PendingReboot.ps1  -ComputerName (Get-Content C:\ADMIN\Scripts\PendingReboot\ExchangeSRV.txt) | select Computer, WindowsUpdate, RebootPending | export-csv C:\temp\Scripts\PendingReboot\Exchange_Server_Pending_Reboot.csv -NoTypeInformation"
      
      ----------------------------------------------------------------------------
  • How to add a reboot at end?
    2 Posts | Last post March 14, 2019
    • Hi Brian,
      Great script buddy. 
      How hard is it to add another bit at end, something like
      if pendingreboot=true Restart-Computer -ComputerName $_
      
      Cheers
      String
      
      
    • did you get the task scheduler working?
      
      do you have to includes these two line ? and how do you specify the folder path to get . .\Get-PendingReboot.ps1 ?
      
      Import-Module .\Get-PendingReboot.ps1
      Import-Module ActiveDirectory
      
  • Condensing the report to only show true values
    5 Posts | Last post February 27, 2019
    • 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
    • Hi MC Nunzio,
      
      I am also looking for the same solution.
      
      Did you get the answer/resolution from anybody?
      
      Thanks
      jignesh
    • Hi MC Nunzio,
      I appreciate the sharing. Question: It works fine within the Powershell prompt, but when I run it via Task Scheduler the results are blank. I get an email but no information. Any Suggestions?
    • @Jignesh
      
      I got the formatting to look better.
      
      
      # Import-Module .\Get-PendingReboot.ps1
      # Import-Module ActiveDirectory
      
      $computers = Get-ADComputer -SearchBase 'OU=Servers,DC=domain,DC=us' -Filter {  Name -like 'ServerName-*'} |Sort-Object name
      
      $Reboots = Test-PendingReboot -Computer $computers.Name |  ConvertTo-Html -Property ComputerName,IsRebootPending -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 = "smtp.domain"
      $smtpFrom = "RebootReport@Provest.us"
      $smtpTo = "user@domain"
      $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)
      
      
  • 32bits ?
    2 Posts | Last post January 04, 2019
    • Hi Brian,
      
      I am trying to use the script with PS 32bits but doesn't work.
      
      How can I make it work ?
      
      Thank you for your help
    • never mind, I had to install the module in x86 envi also and everything works fine.
      
      Thanks
  • How to filter servers only Rebootpending (TRUE)
    2 Posts | Last post October 23, 2018
    • Hi Brian,
      i need only servers which are pending for reboot only() as i used server.txt and has 100+ servers.
      
      Thanks
      Jignesh Kyada
    • Not sure if you have this figured out or not but I use Where-Object to filter this out.
      
      Test-PendingReboot -ComputerName $Server -Credential $Cred | Where{$_.IsRebootPending -eq "true"} | Select Name
  • Invoke-WMIMethod hanging within script from SCCM check
    1 Posts | Last post June 26, 2018
    • I've been troubleshooting a problem when I call this script against a list of computers.  Out of 1800 workstations, I find that this call will indefinitely hang my PSScript for 1 to 4 computers I query.  I've tracked it down to the invoke-wmimethod call it makes to check if SCCM is pending a reboot.  I can only guess that this indefinite hanging has to do with how WMI behaves and not having a default timeout period
      
      Ideally, I would love to have this call timeout after a predefined number has been set but I've been a bit stumped as to how to achieve this.  I'm curious if anyone else has come across this problem and/or has solved this issue.
      
      Thanks!
  • garget group?
    1 Posts | Last post June 18, 2018
    • thanks for a Great script.
      How about pull the list of computer from a target group?
      
  • 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
1 - 10 of 75 Items