Exclusive | Windows Gpupdate
<# .SYNOPSIS Smart gpupdate with logging, reboot control, and remote support. .PARAMETER ComputerName Target computer (default: localhost). Requires PSRemoting. .PARAMETER Force Use /force (default: true) .PARAMETER RebootIfNeeded Automatically reboot if required. .EXAMPLE .\Invoke-GPUpdate.ps1 .\Invoke-GPUpdate.ps1 -ComputerName PC-001 -Force $true -RebootIfNeeded $false #> param( [string]$ComputerName = $env:COMPUTERNAME, [bool]$Force = $true, [bool]$RebootIfNeeded = $false )
:: 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 ) ) windows gpupdate
:: Show current applied policies (without updating) gpresult /r gpresult /scope computer /z | findstr /i "Reboot