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,17 +28,25 @@ Function Update-App ($app) {
|
|||
foreach ($CheckApp in $CheckOutdated) {
|
||||
if ($($CheckApp.Id) -eq $($app.Id)) {
|
||||
|
||||
#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
|
||||
#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
|
||||
& $Winget install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
|
||||
|
||||
#Set mods to apply as an install
|
||||
$ModsMode = "Install"
|
||||
#Set mods to apply as an install
|
||||
$ModsMode = "Install"
|
||||
|
||||
#Check if application installed properly
|
||||
$CheckOutdated2 = Get-WingetOutdatedApps
|
||||
foreach ($CheckApp2 in $CheckOutdated2) {
|
||||
if ($($CheckApp2.Id) -eq $($app.Id)) {
|
||||
$FailedToUpgrade = $true
|
||||
#Check if application installed properly
|
||||
$CheckOutdated2 = Get-WingetOutdatedApps
|
||||
foreach ($CheckApp2 in $CheckOutdated2) {
|
||||
if ($($CheckApp2.Id) -eq $($app.Id)) {
|
||||
$FailedToUpgrade = $true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue