PS Group-Object Feature

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of CHARALABOS CHARALABOS 2 years, 1 month ago.

  • Author
  • #25963
    Profile photo of CHARALABOS

    Hello community

    I'm wondering if is there any cool way-tip to group some objects by property of time range.
    Guess that we have eventlog objects and we want to group them by time range of one hour

    Something like the following:
    For example starting from 00:00 "hour":
    Name Value
    ——– ——–
    01:00 10
    02:00 5
    03:00 15
    04:00 20
    05:00 14


    Thank you in advance!!!

  • #25968
    Profile photo of Peter Jurgens
    Peter Jurgens

    You said it right in your post title! Group-Object!

    For event logs, to group by hour, you can do something like this:

    Get-EventLog -LogName Application -Newest 1000 | Group-Object -Property {$_.TimeWritten.Hour}
  • #25969
    Profile photo of Dave Wyatt
    Dave Wyatt

    Absolutely, but first you have to generate a property with that value to group by (or use a constructed property in the call to Group-Object). Assuming that the objects you want to group have a property named "DateTime", which is a DateTime object, that might look something like this:

    $objects |
    Group-Object -Property { '{0:D2}:00' -f $_.DateTime.Hour }
  • #25973
    Profile photo of CHARALABOS

    Thank you very much!!!

    This really helped !!!

You must be logged in to reply to this topic.