Files
management-scripts/Fix-WindowsUpdate.ps1
T
2019-11-11 19:22:39 -05:00

22 lines
1.1 KiB
PowerShell

# 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 }
# 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 }
# If you're using WSUS this will force a policy update on the device and then
# reset the device's WSUS authorization and start detecting updates
# If you don't use WSUS and Group Policy, you can leave the following line commented out
#Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow"