Select-Object

Select properties of an object or set of objects. Select objects from an array.

Syntax
      Select-Object [[-property] Object[]] [-excludeProperty string[]]
              [-expandProperty string] [-first int] [-last int]
                 [-unique] [-inputObject psobject] [CommonParameters]

Key
   -property Object[]
       The property or properties to select.

   -excludeProperty string
       Properties that will not be selected.
 
   -expandProperty string
       Select and expand the specified property. If the specified property is  
       an array, for example, each value of the array should be included.

   -first int
       Select int number of objects from the beginning of an array of input objects.
        
   -last int
       Select int number of objects from the end of an array of input objects.

   -unique 
       Select unique objects only, (identical properties and values)
		
   -inputObject psobject
       An object or objects to input to Select-Object. May be pipelined.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.

Select-Object will create new objects by copying the values of the selected properties from the input objects.

If the input object is an array, the -First, -Last and -Unique parameters may be used to select particular objects, for more powerful object filtering, use Where-Object.

To add a calculated property to an object, specify a hash table as a value of the -Property parameter. The hash table must include two keys: Name and Expression with the Expression key assigned a script block that will determine the value of the property.

Examples

Display only the name, ID and Working Set(WS) properties of Get-Process:

PS C:\>get-process | select-object ProcessName,Id,WS

Display only the Name and modules properties of Get-Process, use -ExpandProperty to display the details contained within the modules property:

PS C:\>get-process | select-object ProcessName -expandproperty modules | format-list

Display the 5 processes that are using the most memory (WS=Working Set):

PS C:\>get-process | sort-object -property WS | select-object -Last 5

Display the name and claculate the start day of the processes running:

PS C:\>get-process | select-object ProcessName,@{Name="Start Day"; Expression={$_.StartTime.DayOfWeek}}

"A select committee expires on completion of its assigned duties" - Wikipedia

Related Powershell Commands:

Select-String - Search through strings or files for patterns
Compare-Object Compare the properties of objects
ForEach-Object - Loop for each object in the pipeline
Group-Object - Group the objects that contain the same value for a common property
Measure-Object - Measure aspects of object properties and create objects from those values
New-Object - Create a new .Net object
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

Get-Unique - Get the unique items in a collection
Equivalent bash command: gawk - Find and Replace text



Back to the Top

© Copyright SS64.com 1999-2010
Some rights reserved