Files

35 lines
1.6 KiB
PowerShell
Raw Permalink Normal View History

2021-05-24 14:05:59 -04:00
## This is the folder we need to rename
$TARGET_DIR = "${Env:WinDir}\SoftwareDistribution"
2020-08-18 16:20:20 -04:00
2021-05-24 14:05:59 -04:00
## This is what we're renaming it to
$DEST_DIR = "${Env:WinDir}\SoftwareDistribution.old"
2020-10-22 14:01:35 -04:00
2020-08-18 16:20:20 -04:00
## Delete any existing folder from a previous execution of this script
2023-10-05 13:11:38 -04:00
Write-Output "Deleting ""${DEST_DIR}"""
2021-05-24 14:05:59 -04:00
Try { Remove-Item $DEST_DIR -Recurse -Force -ErrorAction SilentlyContinue }
2023-10-05 13:17:18 -04:00
Catch { Write-Error $_.Exception.Message }
2020-08-18 16:20:20 -04:00
## Stop Background Intelligent Transfer Services and Windows Update
2021-05-24 14:05:59 -04:00
Control-Service -Stop -Name BITS
Control-Service -Stop -Name wuauserv
2020-08-18 16:20:20 -04:00
## Rename the SoftwareDistribution folder, forcing Windows Update to recreate all metrics and redownload all updates
2023-10-05 13:11:38 -04:00
Write-Output "Renaming ""${TARGET_DIR}"" to ""${DEST_DIR}"""
2021-05-24 14:05:59 -04:00
Try { Rename-Item -Path $TARGET_DIR -NewName $DEST_DIR -Force }
2023-10-05 13:17:18 -04:00
Catch { Write-Error $_.Exception.Message }
2020-08-18 16:20:20 -04:00
## Start Windows Update and Background Intelligent Transfer Services
2021-05-24 14:05:59 -04:00
Control-Service -Start -Name BITS
Control-Service -Start -Name wuauserv
2020-08-18 16:20:20 -04:00
## Delete SoftwareDistribution.old from this execution of this script
2021-05-24 14:05:59 -04:00
## Comment this section out if you want to leave the renamed folder there for some reason,
## but keep in mind this folder can be very large and takes up a lot of space.
2023-10-05 13:11:38 -04:00
Write-Output "Deleting ""${DEST_DIR}"""
2021-05-24 14:05:59 -04:00
Try { Remove-Item $DEST_DIR -Recurse -Force -ErrorAction SilentlyContinue }
2023-10-05 13:17:18 -04:00
Catch { Write-Error $_.Exception.Message }
2020-08-18 16:20:20 -04:00
2021-05-24 14:05:59 -04:00
## Force the Windows Update client to check for new updates
2023-10-05 13:11:38 -04:00
Write-Output "Resetting WSUS authorization and starting update detection"
2021-05-24 14:05:59 -04:00
Try { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" }
2023-10-05 13:17:18 -04:00
Catch { Write-Error $_.Exception.Message }