Last active
May 20, 2021 07:49
-
-
Save mhupfauer/4985a274993378f536fad4c05844f965 to your computer and use it in GitHub Desktop.
Fix Windows Update on Windows 10 clients managed by SCCM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write-Progress -Activity "Stopping Services" -PercentComplete 1 | |
Stop-Service -Name wuauserv -Force | |
Stop-Service -Name BITS -Force | |
Stop-Service -Name CryptSvc -Force | |
Stop-Service -Name msiserver -Force | |
Write-Progress -Activity "Stopped Services" -PercentComplete 10 | |
Start-Sleep -Seconds 3 | |
$regbase = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\" | |
$toset = @('Active Setup Temp Folders', 'BranchCache', 'D3D Shader Cache', 'Diagnostic Data Viewer database files', | |
'Downloaded Program Files', 'Internet Cache Files', 'Old ChkDsk Files', 'Recycle Bin', 'Setup Log Files', | |
'System error memory dump files', 'System error minidump files', 'Temporary Files', 'Thumbnail Cache', | |
'Update Cleanup', 'Windows Defender', 'Windows Upgrade Log Files') | |
Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\*' ` | |
-Name StateFlags0001 -ErrorAction SilentlyContinue | Remove-ItemProperty -Name StateFlags0001 | |
foreach ($i in $toset) | |
{ | |
New-ItemProperty -Path $regbase$i -Name StateFlags0001 -PropertyType DWord -Value 2 | |
} | |
Write-Progress -Activity "Starting data cleanup" -PercentComplete 11 | |
Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' -WindowStyle Normal -Wait | |
Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process | |
Write-Progress -Activity "Data cleanup complete " -PercentComplete 14 | |
Start-Sleep -Seconds 3 | |
Stop-Service -Name wuauserv -Force | |
Stop-Service -Name BITS -Force | |
Stop-Service -Name CryptSvc -Force | |
Stop-Service -Name msiserver -Force | |
Write-Progress -Activity "Deleting Files" -PercentComplete 14 | |
Remove-Item C:\Windows\SoftwareDistribution -Recurse | |
Remove-Item C:\Windows\System32\catroot2 -Recurse | |
Remove-Item C:\$Windows.~BT -Recurse | |
regsvr32.exe atl.dll | |
regsvr32.exe urlmon.dll | |
regsvr32.exe mshtml.dll | |
regsvr32.exe shdocvw.dll | |
regsvr32.exe browseui.dll | |
regsvr32.exe jscript.dll | |
regsvr32.exe vbscript.dll | |
regsvr32.exe scrrun.dll | |
regsvr32.exe msxml.dll | |
regsvr32.exe msxml3.dll | |
regsvr32.exe msxml6.dll | |
regsvr32.exe actxprxy.dll | |
regsvr32.exe softpub.dll | |
regsvr32.exe wintrust.dll | |
regsvr32.exe dssenh.dll | |
regsvr32.exe rsaenh.dll | |
regsvr32.exe gpkcsp.dll | |
regsvr32.exe sccbase.dll | |
regsvr32.exe slbcsp.dll | |
regsvr32.exe cryptdlg.dll | |
regsvr32.exe oleaut32.dll | |
regsvr32.exe ole32.dll | |
regsvr32.exe shell32.dll | |
regsvr32.exe initpki.dll | |
regsvr32.exe wuapi.dll | |
regsvr32.exe wuaueng.dll | |
regsvr32.exe wuaueng1.dll | |
regsvr32.exe wucltui.dll | |
regsvr32.exe wups.dll | |
regsvr32.exe wups2.dll | |
regsvr32.exe wuweb.dll | |
regsvr32.exe qmgr.dll | |
regsvr32.exe qmgrprxy.dll | |
regsvr32.exe wucltux.dll | |
regsvr32.exe muweb.dll | |
regsvr32.exe wuwebv.dll | |
netsh winsock reset | |
Start-Sleep -Seconds 3 | |
Write-Progress -Activity "Deleted Files" -PercentComplete 15 | |
Start-Sleep -Seconds 3 | |
Write-Progress -Activity "Starting Services" -PercentComplete 16 | |
Start-Service -Name wuauserv | |
Start-Service -Name BITS | |
Start-Service -Name CryptSvc | |
Start-Service -Name msiserver | |
Start-Sleep -Seconds 3 | |
Write-Progress -Activity "Started Services" -PercentComplete 25 | |
#Machine policy | |
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000021}" | |
Write-Progress -Activity "Machine Policy evaluation" -PercentComplete 30 | |
Start-Sleep -Seconds 10 | |
#User policy | |
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000027}" | |
Write-Progress -Activity "User policy evaluation" -PercentComplete 40 | |
Start-Sleep -Seconds 10 | |
#Software update scan cycle | |
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000113}" | |
Write-Progress -Activity "Software update scan" -PercentComplete 80 | |
Start-Sleep -Seconds 10 | |
#Software update deployment cycle | |
Invoke-WMIMethod -Namespace root\ccm -Class SMS_CLIENT -Name TriggerSchedule "{00000000-0000-0000-0000-000000000114}" | |
Write-Progress -Activity "Software update deployment" -PercentComplete 100 | |
Write-Host "Done. Confirm with Enter" | |
Read-Host |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment