From 6709cef6412cc4eb3f1daf3ca28ca49196e4871a Mon Sep 17 00:00:00 2001 From: "Michael H.G. Schmidt" Date: Tue, 30 Jul 2024 12:24:48 +0200 Subject: [PATCH] added show-updates script --- tools/show-updates.cmd | 6 ++++++ tools/show-updates.ps1 | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tools/show-updates.cmd create mode 100644 tools/show-updates.ps1 diff --git a/tools/show-updates.cmd b/tools/show-updates.cmd new file mode 100644 index 0000000..cb310c2 --- /dev/null +++ b/tools/show-updates.cmd @@ -0,0 +1,6 @@ +@echo off +call check-for-admin +if %ERRORLEVEL% neq 0 exit /b + +powershell -command %TOOLS%\show-updates.ps1 + diff --git a/tools/show-updates.ps1 b/tools/show-updates.ps1 new file mode 100644 index 0000000..0ced121 --- /dev/null +++ b/tools/show-updates.ps1 @@ -0,0 +1,43 @@ +# show all updates ... + +function Convert-WuaResultCodeToName { + + param([Parameter(Mandatory=$true)] [int] $ResultCode) + $Result = $ResultCode + + switch($ResultCode) { + 2 { $Result = "Succeeded" } + 3 { $Result = "Succeeded With Errors" } + 4 { $Result = "Failed" } + } + + return $Result +} + +function Get-WuaHistory { + +# Get a WUA Session +$session = (New-Object -ComObject 'Microsoft.Update.Session') + +# Query the latest history starting with the first record +$history = $session.QueryHistory("",0,50) | ForEach-Object { + $Result = Convert-WuaResultCodeToName -ResultCode $_.ResultCode + + # Make the properties (hidden in com properties) visible. + $_ | Add-Member -MemberType NoteProperty -Value $Result -Name Result + $Product = $_.Categories | Where-Object {$_.Type -eq 'Product'} | Select-Object -First 1 -ExpandProperty Name + $_ | Add-Member -MemberType NoteProperty -Value $_.UpdateIdentity.UpdateId -Name UpdateId + $_ | Add-Member -MemberType NoteProperty -Value $_.UpdateIdentity.RevisionNumber -Name RevisionNumber + Write-Output $_ + +} + +# Remove null records and only return the fields we want +$history | + Where-Object {![String]::IsNullOrWhiteSpace($_.title)} | + Select-Object Result, Date, Title + +} + +Get-WuaHistory | Format-Table +