How to Get Windows Update History Using PowerShell?

In this tutorial, I will explain how to get Windows update history using PowerShell. This tutorial will be helpful if you want to keep track of updates across multiple machines. By this end, you will know how to retrieve update history, understand what updates have been applied, and troubleshoot any issues that might arise with Windows updates.

Why Track Windows Update History?

Keeping track of Windows updates is crucial for several reasons:

  1. Security: Ensuring all security patches are applied.
  2. Compliance: Meeting organizational compliance requirements.
  3. Troubleshooting: Diagnosing issues caused by recent updates.
  4. Inventory Management: Keeping an up-to-date record of the software environment.

Note: You need administrative privileges in the system where you want to check.

Get Windows Update History Using PowerShell

First, open PowerShell with administrative privileges. You can do this by searching for “PowerShell” in the Start menu, right-clicking on “Windows PowerShell,” and selecting “Run as administrator.”

Now, let me show you a few methods to get Windows update history using PowerShell.

Using the PSWindowsUpdate Module

The PSWindowsUpdate module is a third-party module that simplifies the management of Windows updates through PowerShell. To use this module, you first need to install it.

Installing PSWindowsUpdate

Install-Module -Name PSWindowsUpdate -Force -SkipPublisherCheck

After installing the module, you need to import it:

Import-Module PSWindowsUpdate

Checking Update History

With the PSWindowsUpdate module installed, you can now check the update history using the Get-WUHistory cmdlet. This cmdlet retrieves a list of updates that have been installed on the system.

Get-WUHistory

This command will display a list of installed updates, including the date of installation, the title of the update, and the result of the installation.

Filtering Results

To make the output more manageable, you can filter the results. For example, if you want to see only the updates installed in the last 30 days, you can use the following command:

Get-WUHistory | Where-Object { $_.Date -gt (Get-Date).AddDays(-30) }

Exporting Update History

You might want to export the update history to a CSV file for reporting purposes. You can do this using the Export-Csv cmdlet:

Get-WUHistory | Export-Csv -Path "C:\Users\Public\Documents\UpdateHistory.csv" -NoTypeInformation

Check out Restart a Windows Service Using PowerShell

Using Built-in PowerShell Cmdlets Get-HotFix

If you prefer not to use third-party modules, you can also retrieve update history using built-in PowerShell cmdlets.

The Get-HotFix cmdlet retrieves information about the hotfixes (updates) that are installed on the local or remote computer.

Get-HotFix

This command provides a list of installed updates, including the description, hotfix ID, and installation date.

Here is the exact output you can see in the screenshot below:

Get Windows Update History Using PowerShell

Example: Filtering by Description

If you want to filter the updates by their description, you can use the Where-Object cmdlet. For example, to find all security updates, you can use:

Get-HotFix | Where-Object { $_.Description -like "*Security*" }

Exporting HotFix Information

Similar to the PSWindowsUpdate module, you can export the hotfix information to a CSV file:

Get-HotFix | Export-Csv -Path "C:\Users\Public\Documents\HotFixHistory.csv" -NoTypeInformation

Check out Install Git on Windows Using PowerShell

Using the Windows Update API

For more advanced users, the Windows Update API provides a way to programmatically access update information. You can use PowerShell to interact with this API.

$UpdateSession = New-Object -ComObject Microsoft.Update.Session
$UpdateSearcher = $UpdateSession.CreateUpdateSearcher()
$HistoryCount = $UpdateSearcher.GetTotalHistoryCount()
$UpdateHistory = $UpdateSearcher.QueryHistory(0, $HistoryCount)

foreach ($Update in $UpdateHistory) {
    Write-Output "Title: $($Update.Title)"
    Write-Output "Date: $($Update.Date)"
    Write-Output "Result: $($Update.ResultCode)"
}

This script creates an update session, queries the update history, and outputs the title, date, and result of each update.

Troubleshooting Update Issues

Sometimes, updates can fail or cause issues. PowerShell can help you troubleshoot these problems.

Checking for Failed Updates

To check for failed updates, you can filter the update history by the result code:

Get-WUHistory | Where-Object { $_.ResultCode -ne 0 }

Removing a Specific Update

If you need to uninstall a problematic update, you can use the wusa.exe command in PowerShell:

wusa.exe /uninstall /kb:1234567 /quiet /norestart

Replace 1234567 with the KB number of the update you want to remove.

Conclusion

In this tutorial, I explained various methods to get Windows update history using PowerShell. You can use the PSWindowsUpdate module, built-in cmdlets like Get-HotFix, or the Windows Update API, etc.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.