PS Group-Object Feature

Welcome Forums General PowerShell Q&A PS Group-Object Feature

This topic contains 3 replies, has 3 voices, and was last updated by

4 years, 3 months ago.

  • Author
  • #25963

    Topics: 15
    Replies: 18
    Points: 0
    Rank: Member

    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

    Topics: 1
    Replies: 111
    Points: 93
    Rank: Member

    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

    Topics: 9
    Replies: 2322
    Points: 0
    Rank: Member

    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

    Topics: 15
    Replies: 18
    Points: 0
    Rank: Member

    Thank you very much!!!

    This really helped !!!

The topic ‘PS Group-Object Feature’ is closed to new replies.