Powershell: A Comprehensive Guide to Retrieving Installed Updates

PowerShell, a powerful task automation and configuration management tool, offers a versatile approach to managing and monitoring Windows systems. Among its many capabilities, PowerShell enables users to effortlessly retrieve a detailed history of installed updates, providing valuable insights into the system’s update status.

Accessing Windows Update History through PowerShell

To access the Windows Update history using PowerShell, follow these steps:

  1. Open PowerShell with Administrative Privileges

    • Press Windows Key + S to open the search bar.
    • Type “PowerShell” and right-click on the result.
    • Select “Run as administrator” to launch PowerShell with elevated permissions.
  2. Retrieve Installed Hotfixes

    • Execute the following command to list all installed hotfixes along with their respective IDs, installation dates, descriptions, and other relevant information:
    Copy
    wmic qfe list
    
  • Obtain Hotfix Descriptions

    • To retrieve a comprehensive list of hotfixes and their associated descriptions, use the following command:
    Copy
    get-wmiobject -class win32_quickfixengineering
    
  • Query Windows Update History

    • PowerShell allows you to query the system for a detailed update history. To do this, define a set of functions to convert Windows Update Agent (WUA) history event result codes into meaningful names and extract crucial information such as the last and latest 50 WUA history entries.
    • Utilize the following function to convert WUA result codes into corresponding names:
    Copy
    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
    }
    
  • Copy
    function Get-WuaHistory
    {
        # Get a WUA Session
        $session = (New-Object -ComObject 'Microsoft.Update.Session')
        # Query the latest 1000 History starting with the first recordp
        $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
            $_ | Add-Member -MemberType NoteProperty -Value $Product -Name Product -PassThru
            Write-Output $_
        }
        #Remove null records and only return the fields we want
        $history |
        Where-Object {!String::IsNullOrWhiteSpace($_.title)} |
        Select-Object Result, Date, Title, SupportUrl, Product, UpdateId, RevisionNumber
    }
    
  • Display Update History

    Copy
    Get-WuaHistory | Format-Table
    
  • This comprehensive guide empowers users to harness the capabilities of PowerShell to retrieve detailed information about installed updates, enabling proactive system management and maintenance.

    FAQ

    What is PowerShell?

    PowerShell is a powerful task automation and configuration management tool built into Windows systems. It enables users to control and automate various aspects of the operating system, including managing updates, configuring settings, and executing scripts.

    How can I retrieve a list of installed hotfixes using PowerShell?

    To retrieve a list of installed hotfixes along with their IDs, installation dates, and descriptions, execute the following command in PowerShell:
    Copy

    wmic qfe list
    

    How do I obtain descriptions for installed hotfixes?

    To obtain comprehensive descriptions for installed hotfixes, use the following command in PowerShell:
    Copy

    get-wmiobject -class win32_quickfixengineering
    

    Can I query the Windows Update history using PowerShell?

    Yes, you can query the Windows Update history using PowerShell. To do this, define a set of functions to convert WUA history event result codes into meaningful names and extract crucial information. Then, utilize the `Get-WuaHistory` function to retrieve the update history.

    How do I display the retrieved update history?

    To display the retrieved update history in a tabular format, execute the following command in PowerShell:
    Copy

    Get-WuaHistory | Format-Table
    

    Leave a Reply

    Your email address will not be published. Required fields are marked *