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.
#---------------------------------------------------------------------------#
# IsWindowsHealthy.ps1 - Run common troubleshooting tools.
# Author - MotoX80 on Microsoft Learn forum.
# Last update - 2025-04-07
# https://learn.microsoft.com/en-us/answers/questions/118183/how-to-fix-error-0x80070543-in-windows-10
#
# The goal of this script is to consolidate all of the typical "look for this" recommendations that
# get posted when someone asks for help with Windows. Example; sfc, dism, chhkdsk, etc.
#
# Any feedback is welcome.
#---------------------------------------------------------------------------#
cls
$color = "Yellow" # Your favorite color
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Available memory analysis "
Write-Host -ForegroundColor $color "------------------------------------------"
$wos = Get-CimInstance -ClassName Win32_OperatingSystem
$tpm = [math]::round($wos.TotalVisibleMemorySize / 1MB, 2)
"Total memory is {0}" -f $tpm | write-host
$fpm = [math]::round($wos.FreePhysicalMemory / 1MB, 2)
"Free memory is {0}" -f $fpm | write-host
# Calculate the percentage of free memory
$freeMemoryPercentage = ($wos.FreePhysicalMemory / $wos.TotalVisibleMemorySize) * 100
if ($freeMemoryPercentage -lt 25) {
Write-Host "You are low on available memory." -ForegroundColor $color
"Free Memory Percentage: {0:N2}%" -f $freeMemoryPercentage | Write-Host -ForegroundColor $color
""
write-host "These processes are using the most memory."
Get-Process | Sort-Object -Property WorkingSet -Descending | Select-Object -First 10 -Property Name, Id, WorkingSet | format-table
} else {
"Free Memory Percentage: {0:N2}%" -f $freeMemoryPercentage | write-host
}
start-sleep -seconds 5
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Boot Details "
Write-Host -ForegroundColor $color "------------------------------------------"
$boot = (Get-CimInstance win32_operatingsystem).LastBootUpTime
"Last boot: {0} ({1} days)" -f $boot, ((get-date) - $boot).days | write-host
$ComputerStatus = new-object -comobject "Microsoft.Update.SystemInfo"
"Reboot required: {0}" -f $ComputerStatus.RebootRequired | write-host
start-sleep -seconds 5
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Crash analysis "
Write-Host -ForegroundColor $color "------------------------------------------"
$days = 7
if (test-path 'C:\ProgramData\Microsoft\Windows\WER\ReportArchive') {
$crashes = Get-ChildItem -Path C:\ProgramData\Microsoft\Windows\WER\ReportArchive -Directory | Sort-Object -Property LastWriteTime -Descending | Where-Object -Property LastWriteTime -gt ((get-date).AddDays(-($days)))
"There have been {0} application crashes in the last {1} days." -f $crashes.count, $days | write-host
$report = @()
foreach ($cf in $crashes) {
$crashdata = Get-Content -Path ($cf.FullName + "\report.wer")
foreach ($line in $crashdata) {
if ($line.StartsWith("OriginalFilename=")) {
$AppName = $line.Substring(17)
}
if ($line.StartsWith("EventType=")) {
$EventType = $line.Substring(10)
}
}
$report += [PSCustomObject]@{
Time = $cf.LastWriteTime
AppName = $AppName
EventType = $EventType
}
}
$report | Format-Table
} else {
write-host "Crash dump folder not found."
}
start-sleep -seconds 5
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}
start-sleep -seconds 5
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
}
start-sleep -seconds 5
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
}
start-sleep -seconds 5
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 -ForegroundColor $color " If you see 'The component store is repairable.'"
Write-Host -ForegroundColor $color " Run 'Dism.exe /online /Cleanup-Image /RestoreHealth'"
Write-Host ""
start-sleep -seconds 5
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"
if ($LASTEXITCODE -ne 0) {break}
start-sleep -seconds 5
Write-Host ""
Write-Host -ForegroundColor $color "------------------------------------------"
Write-Host -ForegroundColor $color " Check the WMI repository "
Write-Host -ForegroundColor $color "------------------------------------------"
winmgmt.exe /verifyrepository
Write-Host ""
Write-Host -ForegroundColor $color "Winmgmt RC=$LASTEXITCODE"
if ($LASTEXITCODE -ne 0) {
Write-Host ""
Write-Host -ForegroundColor $color " Try running 'Winmgmt.exe /salvagerepository'"
Write-Host -ForegroundColor $color " See if that fixes WMI."
Write-Host ""
break
}
start-sleep -seconds 5
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(";")
start-sleep -seconds 5
Write-Host ""
Write-Host -ForegroundColor $color "---------------------------------------------"
Write-Host -ForegroundColor $color " Run the WindowsUpdate Troubleshooting Pack."
Write-Host ""
Write-Host -ForegroundColor $color " If updates are pending, select 'x' to exit."
Write-Host -ForegroundColor $color " Then install the updates when appropriate."
Write-Host -ForegroundColor $color "---------------------------------------------"
Get-TroubleshootingPack -path C:\Windows\diagnostics\system\WindowsUpdate | Invoke-TroubleshootingPack
start-sleep -seconds 5
Write-Host ""
Write-Host -ForegroundColor $color "---------------------------------------------"
Write-Host -ForegroundColor $color " Report on recent updates."
Write-Host -ForegroundColor $color "---------------------------------------------"
Get-CimInstance Win32_QuickFixEngineering | Sort-Object -Property InstalledOn -Descending | Format-Table -Property InstalledOn, HotFixID, Caption
start-sleep -seconds 5
$session = (New-Object -ComObject 'Microsoft.Update.Session')
$history = $session.QueryHistory("",0,1000)
$results = @()
$defender = $history | Where-Object -Property Title -Like "*Defender antivirus*"
"We found {0} Defender updates." -f $defender.count | write-host
$Notdefender = $history | Where-Object -Property Title -NotLike "*Defender antivirus*"
"We found {0} Non-Defender updates." -f $Notdefender.count | write-host
ForEach ($u in $Notdefender) {
switch($u.ResultCode)
{
2 {
$rc = "Succeeded"
}
3 {
$rc = "Succeeded With Errors"
}
4 {
$rc = "Failed"
}
default {
$rc = "Unknown: " + $u.ResultCode
}
}
$results += [PSCustomObject]@{
Date = ($u.Date).ToString('yyyy-MM-dd hh.mm')
Result = $rc
Title = $u.Title
}
}
$results | Format-Table
break
}
Write-Host -ForegroundColor $color "Complete"