Home ยป PowerShell ยป How to Get the Last 30 Days of Windows Updates in PowerShell

How to Get the Last 30 Days of Windows Updates in PowerShell

The PowerShell command to get Windows updates or patches is Get-HotFix. To get the last 30 days of Windows updates, you can use the GetHotFix cmdlet with the Where-Object command to check update installed is greater than 30 days ago.

In this article, we will discuss how to get the last 30 days of Windows updates using the PowerShell script.

PowerShell Script to Get Only Last 30 Days of Windows Updates

Use the Get-HotFix command in PowerShell to get all updates and use the where condition to filter based on the InstalledOn parameter.

# Get the Current date
$currentDate = Get-Date

# Get the date 30 adys ago
$thirtyDaysAgo = $currentDate.AddDays(-30)

# Get all the Updates installed since 30 days ago
Get-HotFix | Where-Object {$_.InstalledOn -gt $thirtyDaysAgo}

In the above PowerShell script, it will first get the current date and then get the date 30 days ago. Lastly, it will use the command Get-HotFix to get all updates installed since 30 days ago and display them.

Cool Tip: How to get the last patch installed date in PowerShell!

Conclusion

I hope the above article on how to get the last 30 days of Windows updates using the PowerShell command Get-HotFix is helpful to you.

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

Leave a Comment