major update

This commit is contained in:
2021-05-24 14:05:59 -04:00
parent 1d882a7ddc
commit e767d39d85
39 changed files with 43 additions and 2272 deletions
+22 -35
View File
@@ -1,48 +1,35 @@
param([switch]$WSUS)
## This is the folder we need to rename
$TARGET_DIR = "${Env:WinDir}\SoftwareDistribution"
LogMsg "Fix-WindowsUpdate.ps1"
## This is what we're renaming it to
$DEST_DIR = "${Env:WinDir}\SoftwareDistribution.old"
## Delete any existing folder from a previous execution of this script
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" )
{
LogMsg "Deleting ""${Env:WinDir}\SoftwareDistribution.old"""
Try { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
Catch { LogErr $_.Exception.Message }
}
LogMsg "Deleting ""${DEST_DIR}"""
Try { Remove-Item $DEST_DIR -Recurse -Force -ErrorAction SilentlyContinue }
Catch { LogErr $_.Exception.Message }
## Stop Background Intelligent Transfer Services and Windows Update
LogMsg "Stopping BITS service"
Try { Stop-Service BITS }
Catch { LogErr $_.Exception.Message }
LogMsg "Stopping wuauserv service"
Try { Stop-Service wuauserv }
Catch { LogErr $_.Exception.Message }
Control-Service -Stop -Name BITS
Control-Service -Stop -Name wuauserv
## Rename the SoftwareDistribution folder, forcing Windows Update to recreate all metrics and redownload all updates
LogMsg "Renaming ""${Env:WinDir}\SoftwareDistribution"" to ""${Env:WinDir}\SoftwareDistribution.old"""
Try { Rename-Item -Path "${Env:WinDir}\SoftwareDistribution" -NewName "${Env:WinDir}\SoftwareDistribution.old" -Force }
LogMsg "Renaming ""${TARGET_DIR}"" to ""${DEST_DIR}"""
Try { Rename-Item -Path $TARGET_DIR -NewName $DEST_DIR -Force }
Catch { LogErr $_.Exception.Message }
## Start Windows Update and Background Intelligent Transfer Services
LogMsg "Starting wuauserv service"
Try { Start-Service wuauserv }
Catch { LogErr $_.Exception.Message }
LogMsg "Starting BITS service"
Try { Start-Service BITS }
Catch { LogErr $_.Exception.Message }
Control-Service -Start -Name BITS
Control-Service -Start -Name wuauserv
## Delete SoftwareDistribution.old from this execution of this script
If ( Test-Path "${Env:WinDir}\SoftwareDistribution.old" )
{
LogMsg "Deleting ""${Env:WinDir}\SoftwareDistribution.old"""
Try { Remove-Item "${Env:WinDir}\SoftwareDistribution.old" -Recurse -Force }
Catch { LogErr $_.Exception.Message }
}
## 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.
LogMsg "Deleting ""${DEST_DIR}"""
Try { Remove-Item $DEST_DIR -Recurse -Force -ErrorAction SilentlyContinue }
Catch { LogErr $_.Exception.Message }
## If using WSUS, reset authorization with server and detect new updates
If ( $WSUS )
{
LogMsg "Resetting WSUS authorization and starting update detection"
Try { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" }
Catch { LogErr $_.Exception.Message }
}
## Force the Windows Update client to check for new updates
LogMsg "Resetting WSUS authorization and starting update detection"
Try { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" }
Catch { LogErr $_.Exception.Message }