Group objects that contain the same value.
Syntax
Group-Object [[-property] Object[]] [-caseSensitive]
[-noElement] [-culture string]
[-inputObject psobject] [CommonParameters]
Key
-property Object[]
The property or list of properties upon which to group.
-caseSensitive
Group upper and lower case values separately.
-noElement
Don't include elements 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.
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.
Examples
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 Commands:
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