HI @JCC ,
Ok, you can limit the alerts to the last 7 days, but this is only possible if your retention settings are set to 7 days. You know that SCOM has two databses - The Operational Database, where tthe data is stored for max 7 days or depending on the data type (see here for more information and details) and afterwards the data is transfered to Data Warehouse where You can get it either using a SQL query (not very user friendly data formating) or using Reports (Reporting Services).
So back to your question - getting the data for the last 7 days. You need to adjust the code slightly:
$GroupName = "Your Group Name Comes Here"
$Group = Get-SCOMGroup -DisplayName $GroupName
$ClassInstance = $Group.GetRelatedMonitoringObjects('Recursive')
$SCOMAlerts = Get-SCOMAlert -Instance $ClassInstance | where {$_.TimeRaised -ge (Get-Date).AddDays(-7)}
$SCOMAlerts
What yosu can also do to speed up the process is to only select Open Alerts (Exclude the closed resolution states) by modifying the script like this:
$GroupName = "Your Group Name Comes Here"
$Group = Get-SCOMGroup -DisplayName $GroupName
$ClassInstance = $Group.GetRelatedMonitoringObjects('Recursive')
$SCOMAlerts = Get-SCOMAlert -Instance $ClassInstance -ResolutionState 0 | where {$_.TimeRaised -ge (Get-Date).AddDays(-7)}
$SCOMAlerts
This will get you all New alerts from the last 7 days, generated by the group in question.
I hope this helps.
(If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
Regards
Stoyan Chalakov