# PS Group-Object Feature

**URL:** <https://forums.powershell.org/t/ps-group-object-feature/4313>\
**Category:** PowerShell Help\
**Created:** [June 4, 2015, 9:14pm UTC](https://forums.powershell.org/t/ps-group-object-feature/4313 "2015-06-04T21:14:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![charalabos-vairlis](https://avatars.discourse-cdn.com/v4/letter/c/8edcca/32.png) [@charalabos-vairlis](https://forums.powershell.org/u/charalabos-vairlis)\
**Post date:** [June 4, 2015, 9:14pm UTC](https://forums.powershell.org/t/ps-group-object-feature/4313/1 "2015-06-04T21:14:29Z")

</div>

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!!!

---

<div class="post-metadata">

**Author:** ![peter-jurgens-2](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@peter-jurgens-2](https://forums.powershell.org/u/peter-jurgens-2)\
**Post date:** [June 4, 2015, 10:40pm UTC](https://forums.powershell.org/t/ps-group-object-feature/4313/2 "2015-06-04T22:40:06Z")

</div>

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}
```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [June 4, 2015, 10:41pm UTC](https://forums.powershell.org/t/ps-group-object-feature/4313/3 "2015-06-04T22:41:22Z")

</div>

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 }
```

---

<div class="post-metadata">

**Author:** ![charalabos-vairlis](https://avatars.discourse-cdn.com/v4/letter/c/8edcca/32.png) [@charalabos-vairlis](https://forums.powershell.org/u/charalabos-vairlis)\
**Post date:** [June 4, 2015, 11:09pm UTC](https://forums.powershell.org/t/ps-group-object-feature/4313/4 "2015-06-04T23:09:32Z")

</div>

Thank you very much!!!

This really helped !!!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:45pm UTC](https://forums.powershell.org/t/ps-group-object-feature/4313/5 "2024-05-16T20:45:14Z")

</div>

Closed on May 16, 2024, 8:45pm UTC


