Windows Update Health Tools is a set of utilities and features developed by Microsoft to help users manage and troubleshoot issues related to Windows Update on their systems.
Windows Update is a crucial component of the Windows operating system that ensures your computer receives the latest security patches, bug fixes, and feature updates from Microsoft.
To make sure all end devices have Microsoft Update Heath tools installed below script is available.
Detection
# Check minimum OS version requirement (1809 or later)
[int]$CurrentBuild = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "CurrentBuildNumber" | Select -ExpandProperty CurrentBuildNumber
If ($CurrentBuild -notin (17763,18363,19041,19042) -and $CurrentBuild -lt 19043)
{
Write-Host "Minimum OS version requirement not met"
Exit 0
}
# Check if Update tools installed
$Results = @()
$UninstallKeys = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
'HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
)
foreach ($key in $UninstallKeys)
{
If (Test-Path $key)
{
$Entry = (Get-ChildItem -Path $key) | Where {$_.GetValue('DisplayName') -eq "Microsoft Update Health Tools"}
If ($Entry)
{
foreach ($item in $Entry)
{
$Results += [PSCustomObject]@{
DisplayName = $item.GetValue("DisplayName")
DisplayVersion = $item.GetValue("DisplayVersion")
InstallDate = $item.GetValue("InstallDate")
GUID = $item.pschildname
}
}
}
}
}
If ($Results.Count -ge 1)
{
foreach ($Result in $Results)
{
Write-Host ($Result | ConvertTo-Json -Compress)
}
Exit 0
}
Else
{
Write-Host "Update Tools not found"
Exit 1
}
Remediation
# variables
$DownloadDirectory = "$env:Temp"
$DownloadFileName = "Expedite_packages.zip"
$LogDirectory = "$env:Temp"
$LogFile = "UpdateTools.log"
# Get the download URL
$ProgressPreference = 'SilentlyContinue'
$URL = "https://www.microsoft.com/en-us/download/confirmation.aspx?id=103324"
$Request = Invoke-WebRequest -Uri $URL -UseBasicParsing
$DownloadURL = ($Request.Links | Where {$_.outerHTML -match "click here to download manually"}).href
# Download and extract the ZIP package
Invoke-WebRequest -Uri $DownloadURL -OutFile "$DownloadDirectory\$DownloadFileName" -UseBasicParsing
If (Test-Path "$DownloadDirectory\$DownloadFileName")
{
Expand-Archive -Path "$DownloadDirectory\$DownloadFileName" -DestinationPath $DownloadDirectory -Force
}
else
{
Write-Host "Update tools not downloaded"
Exit 1
}
# Determine which cab to use
[int]$CurrentBuild = Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name "CurrentBuildNumber" | Select -ExpandProperty CurrentBuildNumber
if ($CurrentBuild -gt 22000)
{
$OSVersion = "Windows 11 22H2+"
}
elseif ($CurrentBuild -eq 22000) {
$OSVersion = "Windows 11 21H2"
}
else
{
$OSVersion = "Windows 10"
}
#[string]$Bitness = Get-CimInstance Win32_OperatingSystem -Property OSArchitecture | Select -ExpandProperty OSArchitecture
#Switch ($Bitness)
#{
# "64-bit" {$arch = "x64"}
# "32-bit" {$arch = "x86"}
# default { Write-Host "Unable to determine OS architecture"; Exit 1 }
#}
#If ($CurrentBuild -eq 22621)
#{
# $CabLocation = "$DownloadDirectory\$($DownloadFileName.Split('.')[0])\$OSVersion\22H2\$arch"
#}
#else
#{
# $CabLocation = "$DownloadDirectory\$($DownloadFileName.Split('.')[0])\$OSVersion\$arch"
#}
#$CabName = (Get-ChildItem $CabLocation -Name *.cab).pschildname
# Expand the cab and get the MSI
#expand.exe /r "$CabLocation\$CabName" /F:* "$DownloadDirectory\$($DownloadFileName.Split('.')[0])"
#Start-Sleep -Seconds 5
#expand.exe /r "$DownloadDirectory\$($DownloadFileName.Split('.')[0])\UpdHealthTools.cab" /F:* "$DownloadDirectory\$($DownloadFileName.Split('.')[0])"
#Start-Sleep -Seconds 5
#$File = Get-Childitem -Path "$DownloadDirectory\$($DownloadFileName.Split('.')[0])\*.msi" -File
# Get MSI file to use
$MsiLocation = "$DownloadDirectory\$($DownloadFileName.Split('.')[0])\$OSVersion"
$File = Get-Childitem -Path "$MsiLocation\*.msi" -File
# Install the MSI
$Process = Start-Process -FilePath msiexec.exe -ArgumentList "/i ""$($File.FullName)"" /qn REBOOT=ReallySuppress /L*V ""$LogDirectory\$LogFile""" -Wait -PassThru
Remove-Item "$DownloadDirectory\$($DownloadFileName.Split('.')[0])" -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item "$DownloadDirectory\$DownloadFileName" -Force -ErrorAction SilentlyContinue
If ($Process.ExitCode -eq 0)
{
Write-Host "Microsoft Update Health tools successfully installed"
Exit 0
}
else
{
Write-Host "Microsoft Update Health tools installation failed with exit code $($Process.ExitCode)"
Exit 1
}
If you liked this post, learned some new things or this article helped you out please think about giving a one time donation at the Donation Page to keep the site online!
Leave a comment