Private/ADLookups/_TestPendingReboot.ps1

function _TestPendingReboot {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        $Identity
    )
    begin {
        $ScriptBlock = { if (Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending' -ErrorAction Ignore) {
                return $true
            }

            if (Get-Item 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired' -ErrorAction Ignore) {
                return $true
            }

            if (Get-ItemProperty 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name PendingFileRenameOperations -ErrorAction Ignore) {
                return $true
            }

            try {
                $util = [wmiclass]'\\.\root\ccm\clientsdk:CCM_ClientUtilities'
                $status = $util.DetermineIfRebootPending()
                if (($null -ne $status) -and $status.RebootPending) {
                    return $true
                }
            }
            catch {
                $MessageSplat = @{
                    MessageText  = "Unable to use CCM Client to get reboot status"
                    MessageIcon  = 'Hand'
                    ButtonType   = 'OK'
                    MessageTitle = 'Error'
                }
                _ShowMessageBox @MessageSplat
            }
            return $false
        }
    }
    process {
        if ($Identity -eq $env:COMPUTERNAME) {
            $Output = Invoke-Command -ScriptBlock $ScriptBlock
        }
        else {
            $Session = New-PSSession -ComputerName $Identity -ErrorAction SilentlyContinue
            If (!($Session)) {
                Return 'Offline'
            }

            $Output = Invoke-Command -Session $Session -ScriptBlock $ScriptBlock
        }
    }
    end {
        return $Output
    }
}