PowerShell Logo Small

Select-Object



This is the built-in help made by Microsoft for the command 'Select-Object', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

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>] [-InputObject <psobject>] [-Last <
int>] [-Skip <int>] [-Unique] [<CommonParameters>]
Select-Object [-Index <Int32[]>] [-InputObject <psobject>] [-Unique] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Select-Object cmdlet gets only the specified properties of an object or set of objects. It can also select unique objects from an array of ob
jects, 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.

Use the Property parameter to specify the properties you want to select. Or, use the First, Last, Unique, Skip, and Index parameters to select pa
rticular objects from an array of input objects. For more specific object filtering, use the Where-Object cmdlet.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113387
Where-Object
Group-Object
Sort-Object

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

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



Description
-----------
This command displays a list of processes. Only the name, ID, and working set (WS) properties of the processes are displayed.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-process | select-object 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:\WINDOWS\system32\00THotkey.exe
BaseAddress : 4194304



Description
-----------
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.








-------------------------- EXAMPLE 3 --------------------------

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

Handles NPM(K) PM(K) WS(K) VS(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
2866 320 33432 45764 203 222.41 1292 svchost
577 17 23676 50516 265 50.58 4388 WINWORD
826 11 75448 76712 188 19.77 3780 Ps
1367 14 73152 88736 216 61.69 676 Ps
1612 44 66080 92780 380 900.59 6132 INFOPATH



Description
-----------
This command displays the five processes that are using the most memory. The Sort-Object cmdlet is used to sort the processes according to memory
(working set) usage, and the Select-Object cmdlet is used to select only the last five members of the resulting array of objects.








-------------------------- EXAMPLE 4 --------------------------

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

ProcessName StartDay
---- --------
alg Wednesday
ati2evxx Wednesday
ati2evxx Thursday
...



Description
-----------
This command displays the name and start day of the processes running on a computer.

The values of the Property parameter are ProcessName and a calculated property named "Start Day." The "Start Day" property is added by using a ha
sh table with Name and Expression keys.








-------------------------- EXAMPLE 5 --------------------------

C:\PS>"a","b","c","a","a","a" | select-object -unique

a
b
c



Description
-----------
This command displays unique characters from an array of characters.








-------------------------- EXAMPLE 6 --------------------------

C:\PS>$a = get-eventlog -log "Windows PowerShell"

C:\PS> $a | select-object -index 0, ($a.count - 1)



Description
-----------
These commands get the first (newest) and last (oldest) events in the Windows Powershell event log.

The first command uses the Get-EventLog cmdlet to get all events in the Windows Powershell log. It saves the events in the $a variable.

The second command uses a pipeline operator (|) to send the events in $a to the Select-Object cmdlet. The Select-Object command uses the Index pa
rameter to select items by their index number. The index for the first event is 0. The index for the last event is the number of items in $a minu
s 1.








-------------------------- EXAMPLE 7 --------------------------

C:\PS>new-pssession -computername (get-content servers.txt | select-object -skip 1)



Description
-----------
This command creates a new PSSession on each of the computers listed in the Servers.txt files, except for the first one.

This command uses the Select-Object cmdlet to select all but the first computer in a list of computer names. The resulting list of computers is s
et as the value of the ComputerName parameter of the New-PSSession cmdlet.