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,68 @@
# Script to stop update-related services, rename folders, and restart services
$LogPath = "C:\Windows\Temp\WUA_Reset.log"
$Services = @("wuauserv", "cryptSvc", "bits", "msiserver")
$SoftwareDistribution = "C:\Windows\SoftwareDistribution"
$SoftwareDistributionOld = "C:\Windows\SoftwareDistribution.old"
$Catroot2 = "C:\Windows\System32\catroot2"
$Catroot2Old = "C:\Windows\System32\catroot2.old"
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
Add-Content -Path $LogPath -Value "$timestamp $Message"
}
# Stop services
foreach ($svc in $Services) {
try {
Write-Log "Stopping service: $svc"
Stop-Service -Name $svc -Force -ErrorAction Stop
} catch {
Write-Log "Failed to stop service $svc: $_"
}
}
Start-Sleep -Seconds 3
# Rename SoftwareDistribution folder
if (Test-Path $SoftwareDistribution) {
try {
if (Test-Path $SoftwareDistributionOld) {
Remove-Item -Path $SoftwareDistributionOld -Recurse -Force
Write-Log "Removed existing $SoftwareDistributionOld"
}
Rename-Item -Path $SoftwareDistribution -NewName "SoftwareDistribution.old"
Write-Log "Renamed $SoftwareDistribution to $SoftwareDistributionOld"
} catch {
Write-Log "Failed to rename $SoftwareDistribution: $_"
}
}
# Rename catroot2 folder
if (Test-Path $Catroot2) {
try {
if (Test-Path $Catroot2Old) {
Remove-Item -Path $Catroot2Old -Recurse -Force
Write-Log "Removed existing $Catroot2Old"
}
Rename-Item -Path $Catroot2 -NewName "catroot2.old"
Write-Log "Renamed $Catroot2 to $Catroot2Old"
} catch {
Write-Log "Failed to rename $Catroot2: $_"
}
}
Start-Sleep -Seconds 2
# Start services
foreach ($svc in $Services) {
try {
Write-Log "Starting service: $svc"
Start-Service -Name $svc -ErrorAction Stop
} catch {
Write-Log "Failed to start service $svc: $_"
}
}
Write-Log "Script completed."

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")
}

View File

@@ -0,0 +1,43 @@
# Reset Windows Update Components (PowerShell)
Two maintained scripts to fix stuck Windows Update on Windows 10/11 and Server:
- **cleanlight.ps1** — quick cache cleanup (fast, minimal).
- **cleanFull.ps1** — full component reset (deeper, reversible).
## What each script does
- `cleanlight.ps1`
- Stops `wuauserv`
- Deletes `%WINDIR%\SoftwareDistribution\Download` and `...\Datastore`
- Restarts `wuauserv`
- Log: `C:\Windows\Temp\Wuauserv_Cleanup.log`
- `cleanFull.ps1`
- Stops `wuauserv`, `bits`, `cryptSvc`, `msiserver`
- Renames `%WINDIR%\SoftwareDistribution``SoftwareDistribution.old`
- Renames `%WINDIR%\System32\catroot2``catroot2.old`
- Restarts services
- Log: `C:\Windows\Temp\WUA_Reset.log`
> Note: Both approaches reset the **local** Windows Update history view. The first scan afterward can be longer.
## Requirements
- Run **as Administrator** on the affected device.
- Use **64-bit** PowerShell path.
- Close the Windows Update UI before running.
## Usage
```powershell
# Light cleanup
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\cleanlight.ps1
# Full reset
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -File C:\Scripts\cleanFull.ps1
```
## After running
- Trigger a scan: `USOClient StartScan` (Win10/11) or wait for the next schedule.
- Optionally delete `*.old` folders after a few days if disk space matters.
- Check logs (paths above) if issues persist; see also `C:\Windows\WindowsUpdate.log` and `C:\Windows\Logs\CBS\CBS.log`.