Windows Gpupdate 〈1000+ PREMIUM〉

$result = Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptBlock -ArgumentList $Force $exitCode = $result.ExitCode "[$(Get-Date)] Exit code: $exitCode" | Out-File -FilePath $logFile -Append Interpret exit codes switch ($exitCode) 0 Write-Host "Success: Policy updated." -ForegroundColor Green 1 Write-Host "Warning: Policy updated but reboot required." -ForegroundColor Yellow 2 Write-Host "Warning: Policy updated but logoff required." -ForegroundColor Yellow 3 Write-Host "Error: Access denied (run as admin)." -ForegroundColor Red default Write-Host "Unknown error code: $exitCode" -ForegroundColor Red Auto-reboot if flagged if ($exitCode -eq 1 -and $RebootIfNeeded -and $ComputerName -eq $env:COMPUTERNAME) Write-Host "Rebooting in 30 seconds..." -ForegroundColor Magenta shutdown /r /t 30 /c "GPUpdate required reboot"

:: Offer to reboot/logoff if "%PENDING%"=="REBOOT" ( echo. choice /c YN /m "Reboot now? " if errorlevel 1 shutdown /r /t 30 /c "GPUpdate requires reboot" exit /b 0 ) if "%PENDING%"=="LOGOFF" ( echo. choice /c YN /m "Logoff now? " if errorlevel 1 shutdown /l exit /b 0 ) windows gpupdate

:: Show pending reboot/logoff echo. echo [INFO] Checking pending actions... gpresult /scope computer /z | findstr /i "Reboot required" > nul if %errorLevel% equ 0 ( echo [ACTION] Computer reboot is REQUIRED. set PENDING=REBOOT ) else ( gpresult /scope user /z | findstr /i "Logoff required" > nul if %errorLevel% equ 0 ( echo [ACTION] User logoff is REQUIRED. set PENDING=LOGOFF ) else ( echo [OK] No reboot or logoff required. set PENDING=NONE ) ) choice /c YN /m "Logoff now