PowerShell - Pending reboots

preview_player
Показать описание
In this video I demonstrate how you can get pending reboot information on Windows using remoting techniques.

*list of servers needing reboot
*reboot pending
*how to detect pending reboots on windows
*powershell
*learn powershell
*automation
*learn automation
*windows
*windows powershell
*automatic deployment
*automatic installations

Code:

Function Get-PendingReboot {
Param(
[Parameter(Mandatory=$True, ValueFromPipeline=$True)] $Machine,
[Parameter(Mandatory=$True)] $creds
)

Try {
Invoke-Command -ComputerName $Machine -Credential $creds -ScriptBlock {
$RebootPending = $False
$baseKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey("LocalMachine", $Machine)

$key = $baseKey.OpenSubKey("Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
$subkeys = $key.GetSubKeyNames()
$key.Close()
If ($subkeys | Where {$_ -eq "RebootPending"}){
$RebootPending = $true
}

$RegWUAU = $baseKey.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
$RegWUAURebootReq = $RegWUAU.GetSubKeyNames()


If ($RegWUAURebootReq | Where {$_ -eq "RebootRequired"})
{
$RebootPending = $true
}
$baseKey.Close()

if(Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager' -Name 'PendingFileRenameOperations' -ErrorAction SilentlyContinue){
$RebootPending = $true
}

$props = @{
rebootPending = $RebootPending
}
New-Object psobject -Property $props
}
}
Catch{
Write-Error "ERROR, trying to get regkey on machine : $Machine, Error returned = $($_.Exception.Message)"
}
}

$creds = Get-Credential
$statusall = [System.Collections.ArrayList]@()
$statusall.Add((Get-PendingReboot -Machine $server -creds $creds))
}

$statusall | select rebootpending, PSComputername

Рекомендации по теме
Комментарии
Автор

Great video buddy and greetings from the UK.Stay safe my friend.

Northfacebloke