Advertisement
Guest User

Function Test-Pending.ps1

a guest
Sep 17th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2.     SRC: https://ilovepowershell.com/2015/09/10/how-to-check-if-a-server-needs-a-reboot/
  3.  
  4. #>
  5.  
  6. #
  7. #Adapted from https://gist.github.com/altrive/5329377
  8. #Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
  9. function Test-PendingReboot
  10. {
  11.  if (Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -EA Ignore) { return $true }
  12.  if (Get-Item "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -EA Ignore) { return $true }
  13.  if (Get-ItemProperty "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -EA Ignore) { return $true }
  14.  try {
  15.    $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
  16.    $status = $util.DetermineIfRebootPending()
  17.    if(($status -ne $null) -and $status.RebootPending){
  18.      return $true
  19.    }
  20.  }catch{}
  21.  
  22.  return $false
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement