Skip to content

Instantly share code, notes, and snippets.

@wictorwilen
Created August 27, 2017 19:00
Show Gist options
  • Save wictorwilen/6b225825f306a3b026769edd1be3cad6 to your computer and use it in GitHub Desktop.
Save wictorwilen/6b225825f306a3b026769edd1be3cad6 to your computer and use it in GitHub Desktop.
Windows Update troubleshooter
## https://support.microsoft.com/en-us/help/971058/how-do-i-reset-windows-update-components
cleanmgr /sageset
cleanmgr /sagerun
$path = "c:\windows\SoftwareDistribution"
# Stopping the wuauserv service
Write-host -foregroundcolor Cyan "1. STOPPING wuauserv service..."
Stop-Service wuauserv
# This is just to make sure the wuauserv service has time to stop before moving
# on to the next portion of the script.
[System.Threading.Thread]::Sleep(2500)
# Testing to see if the c:\windows\SoftwareDistribution folder exists
if (Test-Path $path) {
# If the folder exists Delete it and restart the wuauserv service,
# force WSUS checkin and exit
Write-host -foregroundcolor Red "2. SoftwareDistribution Folder Exists... Deleting"
[System.Threading.Thread]::Sleep(1500)
Remove-Item -path $path -recurse
Write-host -foregroundcolor Red "3. *** DELETED ***"
[System.Threading.Thread]::Sleep(1500)
Write-host -foregroundcolor Cyan "4. STARTING wuauserv service..."
Start-Service wuauserv
[System.Threading.Thread]::Sleep(2500)
Write-host -foregroundcolor Cyan "5. Forcing WSUS Checkin"
[System.Threading.Thread]::Sleep(1500)
Invoke-Command {wuauclt.exe /detectnow}
Write-host -foregroundcolor Cyan "6. Checkin Complete"
} else {
# If the folder does not exist restart the wuauserv service,
# force WSUS checkin and exit
Write-host -foregroundcolor Red "2. SoftwareDistribution Folder does not exists, STARTING wuauserv"
[System.Threading.Thread]::Sleep(1500)
Write-host -foregroundcolor Cyan "3. STARTING wuauserv service..."
Start-Service wuauserv
[System.Threading.Thread]::Sleep(2500)
Write-host -foregroundcolor Cyan "4. Forcing WSUS Checkin"
[System.Threading.Thread]::Sleep(1500)
Invoke-Command {wuauclt.exe /detectnow}
Write-host -foregroundcolor Cyan "5. Checkin Complete"
}
rundll32.exe pnpclean.dll,RunDLL_PnpClean /DRIVERS /MAXCLEAN
DISM.exe /Online /Cleanup-image /Restorehealth
sfc /scannow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment