Here is my IsWindowsHealthy.ps1 file. It tests some of the basic areas that might impact Windows Update. Save it and run it from an admin Powershell prompt. Let's see if it produces any errors.
Update: .ps1 works better than a .bat file.
cls
$color = "Yellow" # Your favorite color
while ($true) {
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Run check disk "
Write-Host -ForegroundColor $color "------------------------------------------"
chkdsk.exe c:
Write-Host ""
Write-Host -ForegroundColor $color "Chkdsk RC=$LASTEXITCODE"
if ($LASTEXITCODE -ne 0) {break}
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Dism CheckHealth "
Write-Host -ForegroundColor $color "------------------------------------------"
Dism.exe /Online /Cleanup-Image /CheckHealth
Write-Host ""
Write-Host -ForegroundColor $color "CheckHealth RC=$LASTEXITCODE"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host -ForegroundColor $color " Try running 'Dism.exe /Online /Cleanup-Image /RestoreHealth'"
Write-Host -ForegroundColor $color " See if that fixes the dism problem."
Write-Host ""
break
}
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Dism ScanHealth"
Write-Host -ForegroundColor $color "------------------------------------------"
Dism.exe /Online /Cleanup-Image /ScanHealth
Write-Host ""
Write-Host -ForegroundColor $color "ScanHealth RC=$LASTEXITCODE"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host -ForegroundColor $color " Try running 'Dism.exe /Online /Cleanup-Image /RestoreHealth'"
Write-Host -ForegroundColor $color " See if that fixes the dism problem."
Write-Host ""
break
}
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Dism AnalyzeComponentstore"
Write-Host -ForegroundColor $color "------------------------------------------"
Dism.exe /online /cleanup-image /AnalyzeComponentstore
Write-Host ""
Write-Host -ForegroundColor $color "AnalyzeComponentstore RC=$LASTEXITCODE"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host -ForegroundColor $color " Try running 'Dism.exe /Online /Cleanup-Image /RestoreHealth'"
Write-Host -ForegroundColor $color " See if that fixes the dism problem."
Write-Host ""
break
}
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor $color " If you see 'Component Store Cleanup Recommended : Yes'"
Write-Host -ForegroundColor $color " Run 'Dism.exe /online /Cleanup-Image /StartComponentCleanup'"
Write-Host ""
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " System File Checker "
Write-Host -ForegroundColor $color "------------------------------------------"
sfc.exe /scannow
Write-Host ""
Write-Host -ForegroundColor $color "SFC RC=$LASTEXITCODE"
Write-Host ""
Write-Host -ForegroundColor $color "--------------------------------------------------"
Write-Host -ForegroundColor $color " Folders in your system path. "
Write-Host -ForegroundColor $color " Remove duplicate entries and to be safe,"
Write-Host -ForegroundColor $color " put the %systemroot% entries first in the list."
Write-Host -ForegroundColor $color "--------------------------------------------------"
$env:Path.split(";")
Write-Host ""
Write-Host -ForegroundColor $color "---------------------------------------------"
Write-Host -ForegroundColor $color " Run the WindowsUpdate Troubleshooting Pack."
Write-Host -ForegroundColor $color "---------------------------------------------"
Get-TroubleshootingPack -path C:\Windows\diagnostics\system\WindowsUpdate | Invoke-TroubleshootingPack
break
}
Write-Host -ForegroundColor $color "Complete"