PowerShell command outputting 'System.__ComObject' on Windows 11 23H2

VM 31 Reputation points
2024-07-02T12:00:45.7933333+00:00

I am working on a Windows 11 23H2 system and attempting to retrieve installed update details using the PowerShell command below, but it's giving me an output of System.__ComObject:

$UpdateSession = New-Object -ComObject 'Microsoft.Update.Session'

$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()

$Updates = $UpdateSearcher.Search('IsInstalled=1')

$result.Updates | Format-Table Title

Attached is a screenshot of the code and output for reference:

User's image

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,272 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,556 Reputation points
    2024-07-02T14:13:23.6733333+00:00

    You have a slight problem because there is no $result variable. That doesn't matter because even if you use the $Updates variable, you still have the same problem. I found that your code works for me on Win10, but fails on my Win11 22H2 laptop.

    To query update history you can use this code.

    $UpdateSession = New-Object -ComObject 'Microsoft.Update.Session'
    $UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
    $UpdateSearcher.QueryHistory(0,100) | format-table -Property ResultCode, Date, Title
    
    
    

    You can also use the PSWindowsUpdate module. Here is what I use.

    # Install-Module -Name PSWindowsUpdate    # run this to install it 
    Get-WUHistory -Last 100 | where-object -Property Title -notlike "Security Intelligence Update*" | format-list -Property Result, Date, Title
    

    Note that Get-WUHistory hangs for me if I don't limit the search with a -Last parameter.