Auto-commit: 2025-10-31 08:55:43
This commit is contained in:
51
reset-windows-update-agent/Cleanuplight.ps1
Normal file
51
reset-windows-update-agent/Cleanuplight.ps1
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user