In.Xi

Skript zur Bereinigung des Windows Update Clients

Der Windows Update Client und Server (wuauctl & wuauserv) sind in Verbindung mit SCCM oft schwer zu debuggen.

Dieses Skript setzt den Zustand des lokalen Windows Update Servers / Clients vollständig zurück.

				
					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 Hidden -Wait
Get-Process -Name cleanmgr,dismhost -ErrorAction SilentlyContinue | Wait-Process
Write-Progress -Activity "Data cleanup complete " -PercentComplete 14

Start-Sleep -Seconds 3

Write-Progress -Activity "Deleting Files" -PercentComplete 14
Remove-Item C:\Windows\SoftwareDistribution -Recurse
Remove-Item C:\windows\System32\catroot2 -Recurse

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 
				
			

Leave a Comment

Mit der Nutzung der Kommentarfunktion stimmen Sie zu, dass Ihr Name, E-Mail Adresse & anonymisierte IP-Adresse zur Verarbeitung auf unserem Server gespeichert werden. Sie können dieses Einverständnis jederzeit widerrufen. Mehr dazu.