major logging overhaul, plus other fixes
This commit is contained in:
+35
-8
@@ -1,21 +1,48 @@
|
||||
param([switch]$WSUS)
|
||||
|
||||
LogMsg "Fix-WindowsUpdate.ps1"
|
||||
|
||||
## 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 }
|
||||
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 }
|
||||
}
|
||||
|
||||
## Stop Background Intelligent Transfer Services and Windows Update
|
||||
Stop-Service BITS
|
||||
Stop-Service wuauserv
|
||||
LogMsg "Stopping BITS service"
|
||||
Try { Stop-Service BITS }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
LogMsg "Stopping wuauserv service"
|
||||
Try { Stop-Service wuauserv }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
|
||||
## 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
|
||||
LogMsg "Renaming ""${Env:WinDir}\SoftwareDistribution"" to ""${Env:WinDir}\SoftwareDistribution.old"""
|
||||
Try { Rename-Item -Path "${Env:WinDir}\SoftwareDistribution" -NewName "${Env:WinDir}\SoftwareDistribution.old" -Force }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
|
||||
## Start Windows Update and Background Intelligent Transfer Services
|
||||
Start-Service wuauserv
|
||||
Start-Service BITS
|
||||
LogMsg "Starting wuauserv service"
|
||||
Try { Start-Service wuauserv }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
LogMsg "Starting BITS service"
|
||||
Try { Start-Service BITS }
|
||||
Catch { LogErr $_.Exception.Message }
|
||||
|
||||
## 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 ( 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 }
|
||||
}
|
||||
|
||||
## If using WSUS, reset authorization with server and detect new updates
|
||||
If ( $WSUS ) { Start-Process "${Env:WinDir}\System32\wuauctl.exe" -ArgumentList "/resetauthorization /detectnow" }
|
||||
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 }
|
||||
}
|
||||
Reference in New Issue
Block a user