Test-PendingReboot
parent
c3c2502e65
commit
03be2cde02
|
@ -0,0 +1,31 @@
|
||||||
|
#Function to check if there's a Pending Reboot
|
||||||
|
|
||||||
|
function Test-PendingReboot {
|
||||||
|
|
||||||
|
$Computer = $env:COMPUTERNAME
|
||||||
|
$PendingReboot = $false
|
||||||
|
|
||||||
|
$HKLM = [UInt32] "0x80000002"
|
||||||
|
$WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv"
|
||||||
|
|
||||||
|
if ($WMI_Reg) {
|
||||||
|
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")).sNames -contains 'RebootPending') {$PendingReboot = $true}
|
||||||
|
if (($WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")).sNames -contains 'RebootRequired') {$PendingReboot = $true}
|
||||||
|
|
||||||
|
#Checking for SCCM namespace
|
||||||
|
$SCCM_Namespace = Get-WmiObject -Namespace ROOT\CCM\ClientSDK -List -ComputerName $Computer -ErrorAction Ignore
|
||||||
|
if ($SCCM_Namespace) {
|
||||||
|
if (([WmiClass]"\\$Computer\ROOT\CCM\ClientSDK:CCM_ClientUtilities").DetermineIfRebootPending().RebootPending -eq $true) {$PendingReboot = $true}
|
||||||
|
}
|
||||||
|
|
||||||
|
# [PSCustomObject]@{
|
||||||
|
# ComputerName = $Computer.ToUpper()
|
||||||
|
# PendingReboot = $PendingReboot
|
||||||
|
# }
|
||||||
|
}
|
||||||
|
$null = $WMI_Reg
|
||||||
|
$null = $SCCM_Namespace
|
||||||
|
|
||||||
|
return $PendingReboot
|
||||||
|
|
||||||
|
}
|
|
@ -28,6 +28,13 @@ Function Update-App ($app) {
|
||||||
foreach ($CheckApp in $CheckOutdated) {
|
foreach ($CheckApp in $CheckOutdated) {
|
||||||
if ($($CheckApp.Id) -eq $($app.Id)) {
|
if ($($CheckApp.Id) -eq $($app.Id)) {
|
||||||
|
|
||||||
|
#Upgrade failed for a reason? Check for a Pending Reboot (Component Based Servicing/WindowsUpdate/CCM_ClientUtilities)
|
||||||
|
$PendingReboot = Test-PendingReboot
|
||||||
|
if ($PendingReboot) {
|
||||||
|
$FailedToUpgrade = $true
|
||||||
|
Write-Log "A Pending Reboot prohibited $($app.Id) from upgrading..." "Red"
|
||||||
|
}
|
||||||
|
else {
|
||||||
#If app failed to upgrade, run Install command
|
#If app failed to upgrade, run Install command
|
||||||
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
||||||
|
|
||||||
|
@ -43,6 +50,7 @@ Function Update-App ($app) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($FailedToUpgrade -eq $false) {
|
if ($FailedToUpgrade -eq $false) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue