Home ยป PowerShell ยป PowerShell Get Last Patch Date

PowerShell Get Last Patch Date

Use the Get-HotFix cmdlet in PowerShell to get last patch date, this command retrieves a list of all patches that have been installed on the Windows OS.

PowerShell provides tools and commands for managing Windows systems including monitoring and controlling the patch installation. You can use PowerShell to retrieve the last patch date to ensure your system is up-to-date and secure.

In this article, we will discuss how to use PowerShell Get-HotFix to get the last patch date and how to retrieve installed updates.

Using Get-HotFix to Retrieve Installed Updates

To retrieve a list of installed updates, we can use the Get-HotFix cmdlet in PowerShell.

Get-HotFix

In the above PowerShell script, the Get-HotFix cmdlet will return a list of all patches installed on the Windows OS.

The output of the above script displays a list of all patches installed:

PowerShell Get All Patches
PowerShell Get All Patches

Get HotFix Sort by Date in PowerShell

The Get-HotFix cmdlet provides a list of all patches installed on the system. To check the most recently installed patches, use the sort operation on the โ€œInstalledOnโ€ property.

Get-HotFix | Sort-Object InstalledOn -Descending

In the above PowerShell script, the Get-HotFix command retrieves a list of all patches and sends it to the Sort-Object to sort the output by the InstalledOn property in descending order.

The output of the above PowerShell script get the hotfix sort by date.

PS C:\> Get-HotFix | Sort-Object InstalledOn -Descending                                                                                          
Source        Description      HotFixID      InstalledBy          InstalledOn
------        -----------      --------      -----------          -----------
INCORP-EU Update           KB4589211     NT AUTHORITY\SYSTEM  12-05-2023 00:00:00
INCORP-EU Update           KB5013627     NT AUTHORITY\SYSTEM  02-08-2022 00:00:00
INCORP-EU Security Update  KB5013945     NT AUTHORITY\SYSTEM  30-05-2022 00:00:00
INCORP-EU Security Update  KB5014029     NT AUTHORITY\SYSTEM  29-05-2022 00:00:00

Get the Last Patch Installed Date in PowerShell

We can retrieve the last patch date by selecting the top item from the list that contains the sorted list of installed patches.

$LastPatch = Get-HotFix | Sort-Object InstalledOn -Descending | Select-Object -First 1 

In the above PowerShell script, the Get-HotFix cmdlet retrieves a list of all updates on the system and pipes them to the Sort-Object command to sort the list in descending order by InstalledOn property and use the Select-Object cmdlet to get the top 1 record that contains the last patch date and its information.

The output of the above PowerShell script to retrieve the last patch installed date is:

PowerShell Get the Last Patch Date
PowerShell Get the Last Patch Date

Cool Tip: How to check installed patches in Windows using PowerShell!

Conclusion

I hope the above article on how to get the last patch date in PowerShell using the Get-HotFix command is helpful to you.

Using the Get-HotFix and Sort-Object cmdlets in PowerShell, you can monitor the patch status of your systems and ensure the system is up to date.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.