Count all alerts, group by date


Count all alerts, group by date

$array = @();foreach ($date in Get-Alert | foreach-object {$_.get_TimeRaised().ToLocalTime().toShortDateString()}) {$array += $date};$array | Group-Object | select-object count,@{name="Date";expression={foreach-object {$_.name}}} | sort-object date –desc

main menu


Comments (4)

  1. Anonymous says:

    More or less the same as here

    http://www.muscetta.com/2008/01/25/looking-at-opsmgr2007-alert-trend-with-command-shell/

    Only issue with this approach (both mine and yours) is that it is painfully SLOW on big deployments. The SQL Queries on Kevin’s blog are much better for performance :-)

  2. Anonymous says:

    If you are in any time zone other than GMT and you do not do a Date-Time conversion, the results will be inaccurate, regardless of how many MG’s you have and which time zones they span.

    You can see this proven by changing the time zone on your workstation and running the script in this post.  Then, run the script in your post.  The results will be different.

    btw – I think I borrowed the framework for this one from your post. :-)

  3. Anonymous says:

    I wrote that a long time ago (waaaay before blogging it). And yes, you are right: I did not take into account time zones, as I was testing that it italy, which is GMT+1… If your management group does not span multiple countries, you should be nearly alright :-)

  4. Anonymous says:

    Thanks for the comment, Daniele.

    One major difference in my script is it performs a Date-Time conversion.  Performing this DT conversion ensures accuracy in the results.  See more on that here.

    Command Shell: Be careful with Date-Time criteria and
    calculations

    As far as performance, this is true.  But the Command Shell is another option for those that do not have permissions to query SQL directly.

    -Jonathan