Powershell List of Updates Result Indicates "In Progress" after v2004 Upgrade

I have been playing around with Powershell for a while and just for fun generated a report of Windows Updates. I have been running this for several years and it has worked well. Ever since the upgrade to v2004, the “Result” value for cumulative updates is coming up with a value of “1” (“In Progress”) instead of “2” which indicates the update “Succeeded” while all other updates (.NET, Office, etc.) display the proper “Succeeded” value. If I view the Updates History in “Settings”, it shows that the cumulative updates have been successfully installed. I also noticed that now the “Restart” button appears before the cumulative update is finished installing. Is it possible that this premature “Restart” button is causing the wrong code to be generated for the cumulative updates?


Can’t really comment on why your code is reporting something without having a clue what your code is.

Here are the relevant lines:

$wu = new-object -com “Microsoft.Update.Searcher”
$totalupdates = $wu.GetTotalHistoryCount()

if ($totalupdates -eq 0) {
Write-Host "*"
Write-Host “*** No Updates Found, Job Terminated ***”
Write-Host "*"
} else {

$all = $wu.QueryHistory(0,$totalupdates)

# Define a new array to gather output

$OutputCollection= @()                                                  # Establish array to contain KB data

Foreach ($update in $all) {

$kb_title = $update.title                                                   # Get KB Title
$kb_date = $update.date.ToLocalTime()                      # Get KB Date

$oper = $update.Operation                                               # Get KB Operation

# Convert Operation Nbr to string
if ($oper -eq 1) {$prt_oper = "Install"
} elseif ($oper -eq 2) {$prt_oper = "UnInstall"
} else {$prt_oper = "Other"

$res_cd = $update.ResultCode                                           # Get KB Result Code

# Convert ResultCode Nbr to string
if ($res_cd -eq 0) {$prt_res_cd = "Not Started"
} elseif ($res_cd -eq 1) {$prt_res_cd = "In Progress"
} elseif ($res_cd -eq 2) {$prt_res_cd = "Succeeded"
} elseif ($res_cd -eq 3) {$prt_res_cd = "Succeeded w/Errors"
} elseif ($res_cd -eq 4) {$prt_res_cd = "Failed"
} else {$prt_res_cd = "Aborted"