21 lines
1.0 KiB
PowerShell
21 lines
1.0 KiB
PowerShell
param([switch]$WSUS)
|
|
|
|
## Delete any existing folder from a previous execution of this script
|
|
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" ) { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
|
|
|
|
## Stop Background Intelligent Transfer Services and Windows Update
|
|
Stop-Service BITS
|
|
Stop-Service wuauserv
|
|
|
|
## Rename the SoftwareDistribution folder, forcing Windows Update to recreate all metrics and redownload all updates
|
|
Rename-Item -Path "${Env:WinDir}\SoftwareDistribution" -NewName "${Env:WinDir}\SoftwareDistribution.old" -Force
|
|
|
|
## Start Windows Update and Background Intelligent Transfer Services
|
|
Start-Service wuauserv
|
|
Start-Service BITS
|
|
|
|
## Delete SoftwareDistribution.old from this execution of this script
|
|
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" ) { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
|
|
|
|
## If using WSUS, reset authorization with server and detect new updates
|
|
If ( $WSUS ) { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" } |