Group objects that contain the same value.

      Group-Object [-AsHashTable] [-AsString] [[-property] Object[]]
         [-caseSensitive] [-noElement] [-culture string]
            [-inputObject psobject] [CommonParameters]

       Return the group as a hash table.
       The keys of the hash table are the property values by which the objects are grouped.
       The values of the hash table are the objects that have that property value.

       By itself, -AsHashTable returns each hash table in which each key is an instance
       of the grouped object. When used with -AsString, the keys in the hash table are strings.

       Convert the hash table keys to strings.
       By default, the hash table keys are instances of the grouped object.
       This parameter is valid only when used with -AsHashTable.

   -property Object[]
       The property or list of properties upon which to group.
       The value of -Property can be a new calculated property.
       To create a calculated, property, create a hash table with an Expression key
       that specifies a string or script block value.

       Make the grouping case-sensitive.
       e.g. Test, TEST and TesT would become separate groups.
       Don't include members of each group in the output objects.

   -culture string
       The culture to use when performing a string comparison.
   -inputObject psobject
       The objects to group. May be pipelined.
       A variable command or expression that gets the objects.
       To group the objects in a collection, pipe the objects to Group-Object.

Standard Aliases for Group-Object: group


Display a list of files grouped by size:

PS C:\> get-childitem *.doc | group-object -property length

Display a list of files, sorted and then grouped by the file extension:

PS C:\> get-childitem | sort-object -property extension | group-object -property extension

Count the file extensions (in the current directory) without retrieving all the files:

PS C:\> get-childitem | group-object extension -noelement

“If we are together nothing is impossible. If we are divided all will fail” ~ Winston Churchill

Related PowerShell Cmdlets:

Compare-Object Compare the properties of objects.
ForEach-object - Loop for each object in the pipeline.
Measure-Object - Measure aspects of object properties and create objects from those values.
New-Object - Create a new .Net object
Select-Object - Select objects based on parameters set in the Cmdlet command string.
Sort-Object - Sort the input objects by property value.
Tee-Object - Send input objects to two places.
Where-Object - Filter input from the pipeline allowing operation on only certain objects

Copyright © 1999-2020
Some rights reserved