Test-PendingReboot.ps1

function Test-PendingReboot
{
  <#
    .SYNOPSIS
    Queries a computer and retuns [bool] if a restart is requried.
    .DESCRIPTION
    #Adapted from https://gist.github.com/altrive/5329377
    #Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
    #Modified by Mike Riston to support remote computer queries and support arrays in $computer value. 2017.06.22
    .EXAMPLE
    Test-PendingReboot
    Returns True/False against localhost
    .EXAMPLE
    Test-PendingReboot -computer DC01
    Returns True/False against DC01
    .EXAMPLE
    Test-PendingReboot -computer DC01,DC02
    Returns True/False against DC01 and DC02
      PS > Test-PendingReboot -computer DC01,DC02
      DC01:True
      DC02:True
 
  #>

  [CmdletBinding()]
  param
  (
    [Parameter(Mandatory=$false, Position=0)]
    [Object[]]
    $computer = ('localhost')
  )
  
  $sb = {
    if (Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' -EA SilentlyContinue) 
    {
      return "$($env:COMPUTERNAME.PadRight(20))$($true)"
    }
    if (Get-Item 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' -EA SilentlyContinue ) 
    {
      return "$($env:COMPUTERNAME.PadRight(20))$($true)"
    }
    if (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name PendingFileRenameOperations -EA SilentlyContinue) 
    {
      return "$($env:COMPUTERNAME.PadRight(20))$($true)"
    }
    try 
    {
      $util = [wmiclass]'\\.\root\ccm\clientsdk:CCM_ClientUtilities'
      $status = $util.DetermineIfRebootPending()
      if(($status -ne $null) -and $status.RebootPending)
      {
        return "$($env:COMPUTERNAME.PadRight(20))$($true)"
      }
    }
    catch
    {
      
    }
    
    return "$($env:COMPUTERNAME.PadRight(20))$($false)"
  }
  Write-Output 'Output Format'
  Write-Output 'COMPUTERNAME:[bool]'
  foreach ($c in $computer) {
    Invoke-Command -ComputerName $c -ScriptBlock $sb
  }
}