Auto-commit: 2025-10-31 08:55:43

This commit is contained in:
David Wuibaille
2025-10-31 08:55:43 +01:00
parent 9bb5ad24bb
commit 24c0c6509f
33 changed files with 13144 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
$global:LogPath = "C:\Windows\Temp\Wuauserv_Cleanup.log"
$ServiceName = "wuauserv"
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content -Path $global:LogPath -Value "$timestamp $Message"
write-host $Message
}
function Clean-WUClientFolders {
Write-Log "Cleaning up Windows Update client folders"
$windir = $env:WINDIR
$WUDownload = Join-Path $windir "SoftwareDistribution\Download"
$WUDataStore = Join-Path $windir "SoftwareDistribution\Datastore"
if (Test-Path $WUDownload) {
try {
Remove-Item $WUDownload -Recurse -Force
Write-Log "Deleted $WUDownload"
} catch {
Write-Log ("Failed to delete $WUDownload")
}
}
if (Test-Path $WUDataStore) {
try {
Remove-Item $WUDataStore -Recurse -Force
Write-Log "Deleted $WUDataStore"
} catch {
Write-Log ("Failed to delete $WUDataStore")
}
}
}
try {
Write-Log "Stopping $ServiceName"
Stop-Service -Name $ServiceName -Force -ErrorAction Stop
Start-Sleep -Seconds 3
} catch {
Write-Log ("Failed to stop $ServiceName")
}
Clean-WUClientFolders
try {
Write-Log "Starting $ServiceName"
Start-Service -Name $ServiceName -ErrorAction Stop
Write-Log "$ServiceName started"
} catch {
Write-Log ("Failed to start $ServiceName")
}