PS Group-Object Feature

This topic contains 3 replies, has 3 voices, and was last updated by  CHARALABOS 2 years, 4 months ago.

  • Author
    Posts
  • #25963

    CHARALABOS
    Participant

    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

    etc

    Thank you in advance!!!

  • #25968

    Peter Jurgens
    Participant

    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

    Dave Wyatt
    Moderator

    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

    CHARALABOS
    Participant

    Thank you very much!!!

    This really helped !!!

You must be logged in to reply to this topic.