Get all alerts within a certain time period

A co-worker of mine ran into an alert flood scenario and needed to resolve a large number of alerts. He tried the following PowerShell command:

Get-Alert | where {$_.ResolutionState -eq “New”} | Resolve-Alert

This eventually ended up throwing an out of memory exception. This command is obviously attempting to resolve all of the alerts from the flood at once. Another alternative would be to resolve them in chunks. I provided a script that retrieves all alerts that were raised within the last 30 minutes. This can be modified to get only new alerts, set the resolution state of each alert, and also get the alerts from the past hour, day, month, etc…

I usually also append | Out-Null to the Resolve-Alert cmdlet. having to display the output in the console greatly reduces the performance of the command shell… while suppressing output really speeds it up.

But it is true that when manipulating many objects in powershell you can run out of memory pretty easily if you don’t pay attention.