Select-Object

Selects objects or object properties.
Select-Object [[-Property] [<Object[]>]] [-ExcludeProperty [<String[]>]] [-ExpandProperty [<String>]][-InputObject [<PSObject>]] [-Last [<Int32>]] [-Unique] [-Wait] [-First [<SwitchParameter>]] [-Skip[<SwitchParameter>]] [-IncludeTotalCount [<SwitchParameter>]] [<CommonParameters>]
Select-Object [-Index [<Int32[]>]] [-InputObject [<PSObject>]] [-Unique] [-Wait] [-First [<SwitchParameter>]][-Skip [<SwitchParameter>]] [-IncludeTotalCount [<SwitchParameter>]] [<CommonParameters>]
Select-Object [-SkipLast [<Int32>]] [-First [<SwitchParameter>]] [-Skip [<SwitchParameter>]] [-IncludeTotalCount[<SwitchParameter>]] [<CommonParameters>]

The Select-Object cmdlet selects specified properties of an object or set of objects. It can also select unique objects, a specified number of objects, or objects in a specified position in an array.

To select objects from a collection, use the First, Last, Unique, Skip, and Index parameters. To select object properties, use the Property parameter. When you select properties, this cmdlet returns new objects that have only the specified properties.

Beginning in Windows PowerShell 3.0, Select-Object includes an optimization feature that prevents commands from creating and processing objects that are not used. When you include a Select-Object command with the First or Index parameter in a command pipeline, Windows PowerShell stops the command that generates the objects as soon as the selected number of objects is generated, even when the command that generates the objects appears before the Select-Object command in the pipeline. To turn off this optimizing behavior, use the Wait parameter.

Parameters
-ExcludeProperty [<String[]>]

Removes the specified properties from the selection. Wildcards are permitted. This parameter is effective only when the command also includes the Property parameter.

-ExpandProperty [<String>]

Specifies a property to select, and indicates that an attempt should be made to expand that property. Wildcards are permitted in the property name.

For example, if the specified property is an array, each value of the array is included in the output. If the property contains an object, the properties of that object are displayed in the output.

-Index [<Int32[]>]

  • Default value is None

Selects objects from an array based on their index values. Enter the indexes in a comma-separated list.

Indexes in an array begin with 0, where 0 represents the first value and (n-1) represents the last value.

-InputObject [<PSObject>]

Specifies objects to send to the cmdlet through the pipeline. This parameter enables you to pipe objects to Select-Object.

When you use the InputObject parameter with Select-Object, instead of piping command results to Select-Object, the InputObject value-even if the value is a collection that is the result of a command, such as -InputObject (Get-Process)-is treated as a single object. Because InputObject cannot return individual properties from an array or collection of objects, it is recommended that if you use Select-Object to filter a collection of objects for those objects that have specific values in defined properties, you use Select-Object in the pipeline, as shown in the examples in this topic.

-Last [<Int32>]

Specifies the number of objects to select from the end of an array of input objects.

-Property [<Object[]>]

Specifies the properties to select. Wildcards are permitted.

The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:

— Name (or Label) <string>

— Expression <string> or <script block>

-SkipLast [<Int32>]
 
-Unique [<SwitchParameter>]

Specifies that if a subset of the input objects has identical properties and values, only a single member of the subset will be selected.

This parameter is case-sensitive. As a result, strings that differ only in character casing are considered to be unique.

-Wait [<SwitchParameter>]

Indicates that the cmdlet turns off optimization. Windows PowerShell runs commands in the order that they appear in the command pipeline and lets them generate all objects. By default, if you include a Select-Object command with the First or Index parameters in a command pipeline, Windows PowerShell stops the command that generates the objects as soon as the selected number of objects is generated.

This parameter was introduced in Windows PowerShell 3.0.

-First [<SwitchParameter>]

  • Default value is false

Gets only the specified number of objects. Enter the number of objects to get.

-Skip [<SwitchParameter>]

  • Default value is false

Ignores the specified number of objects and then gets the remaining objects. Enter the number of objects to skip.

-IncludeTotalCount [<SwitchParameter>]

  • Default value is false

Reports the total number of objects in the data set (an integer) followed by the selected objects. If the cmdlet cannot determine the total count, it displays “Unknown total count.” The integer has an Accuracy property that indicates the reliability of the total count value. The value of Accuracy ranges from 0.0 to 1.0 where 0.0 means that the cmdlet could not count the objects, 1.0 means that the count is exact, and a value between 0.0 and 1.0 indicates an increasingly reliable estimate.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs

System.Management.Automation.PSObject

You can pipe any object to Select-Object.

Outputs

System.Management.Automation.PSObject

Examples
  1. Select objects by property:
    PS C:> Get-Process | Select-Object -Property ProcessName, Id, WS
    

    This command creates objects that have the Name, ID, and working set (WS) properties of process objects.

  2. Select objects by property and format the results:
    PS C:> Get-Process Explorer | Select-Object -Property ProcessName -ExpandProperty Modules | Format-List

    ProcessName : 00THotkey
    Size : 256
    Company : TOSHIBA Corporation
    FileVersion : 1, 0, 0, 27
    ProductVersion : 6, 2, 0, 0
    Description : THotkey
    Product : TOSHIBA THotkey
    ModuleName : 00THotkey.exe
    FileName : C:WINDOWSsystem32