Select-Object

 

Additional Resources for Select-Object

 

Selecting Specific Properties of an Object

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/select-object.mspx

 

 

SYNOPSIS

Selects specified properties of an object or set of objects. It can also select unique objects from an array of objects or it can select a specified number of objects from the beginning or end of an array of objects.

 

SYNTAX

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

 

DETAILED DESCRIPTION

Selects specified properties of an object or set of objects. It can also select unique objects from an array of objects or it can select a specified number of objects from the beginning or end of an array of objects.

 

If you use Select-Object to select specified properties, it copies the values of those properties from the input objects and creates new objects that have the specified properties and copied values. You can use the First, Last and Unique parameters to select particular objects from an array of input objects. For more powerful object filtering, use the Where-Object cmdlet.

 

You can use Select-Object to add calculated properties to an object. To do so, you specify a hash table as a value of the Property parameter. The hash table must include two keys: Name and Expression. The value assigned to the Name key is used as the name of the property. The Expression key is assigned a script block that is evaluated to determine the value of the property.

 

PARAMETERS

 

-property <Object[]>

Specifies a property or properties to select. You can use wildcards in values for this parameter.

 

Required?

false

Position?

1

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-excludeProperty <string[]>

Specifies a property or properties that should not be selected. Excluded properties are removed after included properties are selected.

 

Required?

false

Position?

named

Default value

null

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-expandProperty <string>

Specifies a property to selected and indicates that an attempt should be made to expand that property. If the specified property is an array, for example, each value of the array should be included.

 

Required?

false

Position?

named

Default value

null

Accept pipeline input?  

false

Accept wildcard characters? 

true

 

-first <int>

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

 

Required?

false

Position?

named

Default value

0

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-last <int>

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

 

Required?

false

Position?

named

Default value

0

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-unique <SwitchParameter>

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

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-inputObject <psobject>

Specifies an object or objects to input to the cmdlet.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

true (ByValue)

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

Object[]

 

RETURN TYPE

PSObjects

 

NOTES

 

For more information, type "Get-Help Select-Object  -detailed". For technical information, type "Get-Help Select-Object -full".

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>". You can also refer to Select-Object by its built-in alias, "select". For more information, see About_Alias.

 

EXAMPLE 1

 

get-process | select-object ProcessName,Id,WS

 

This command displays a list of processes. Only the name, ID and Working Set(WS) properties of the processes are displayed.

 

EXAMPLE 2

 

get-process | select-object processname -expandproperty modules |

format-list

 

This command displays information about the modules used by the processes running on a computer. It uses the ExpandProperty parameter to display the details contained within the modules property.

 

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:\WINDOWS\system32\00THotkey.exe

BaseAddress   : 4194304

 

EXAMPLE 3

 

get-process | sort-object -property WS | select-object -Last 5

 

This command displays the 5 processes that are using the most memory. The Sort-Object cmdletis used to sort the processes according to memory (Working Set) usage and the Select-Object cmdlet is used to select only the last 5 members of the resulting array of objects.

 

Handles  NPM(K)PM(K)  WS(K)  VS(M)   CPU(s)     Id   ProcessName

-------  -----------  -----  -----   ------     --   -----------

   2866  32033432     45764    203   222.41   1292   svchost

    577  1723676      50516    265    50.58   4388   WINWORD

    826  1175448      76712    188    19.77   3780   Ps

   1367  1473152      88736    216     61.6   9676   Ps

   1612  4466080      92780    380   900.59   6132   INFOPATH

 

EXAMPLE 4

 

$processes = get-process | select-object ProcessName,@{Name="Start Day";Expression = {$_.StartTime.DayOfWeek}}

 

This command displays the name and start day of the processes running on a computer. Processname is a property of the objects output by the Get-Process cmdletand start day is a calculated property.

 

Name       StartDay

----       --------

alg        Wednesday

ati2evxx   Wednesday

ati2evxx   Thursday

...

 

EXAMPLE 5

 

"a","b","c","a","a","a" | select-object -unique

 

This command displays unique characters from an array of characters.

 

a

b

c

 

RELATED LINKS

Where-Object

Group-Object

Sort-Object