You are currently viewing PowerShell Group-Object Cmdlet

PowerShell Group-Object Cmdlet

PowerShell Group-Object Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Select-Object cmdlet in PowerShell.

https://cloudaffaire.com/powershell-select-object-cmdlet/

In this blog post, we will discuss Group-Object cmdlet in PowerShell. You can use Group-Object cmdlet to group objects based on a specific object property. The output of the Group-Object will contain a column indicating the number of items in that group along with the rows for each property values. You can also use Group-Object cmdlet to group based on multiple property. In this case the Group-Object will group the output based on the 1st property and within each groups it will create subgroups based on the second property and this will continue based on the number of secondary property that has been defined.

Group-Object Cmdlet Syntax:

Group-Object Cmdlet Argument List:

  • AsHashTable: Indicates that this cmdlet returns the group as a hash table.
  • AsString: Indicates that this cmdlet converts the hash table keys to strings.
  • CaseSensitive: Indicates that this cmdlet makes the grouping case-sensitive.
  • Culture: Specifies the culture to use when comparing strings.
  • InputObject: Specifies the objects to group.
  • NoElement: Indicates that this cmdlet omits the members of a group from the results.
  • Property: Specifies the properties for grouping.

PowerShell Group-Object Cmdlet:

Group Objects Based On Single Property In PowerShell:

Group Objects Based On Multiple Properties In PowerShell:

Omit The Grouping Information In Group-Object Output:

Get Output Of Group-Object cmdlet In Hash Table:

Hope you have enjoyed this article. In the next blog post, we will discuss the Sort-Object cmdlet in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply