PowerShell Select-Object Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed New-Object cmdlet in PowerShell.
https://cloudaffaire.com/powershell-new-object-cmdlet/
In this blog post, we will discuss Select-Object cmdlet in PowerShell. You can use Select-Object cmdlet to select specific properties of object in the output. You can further limit the number of results in the output using ‘First’, ‘Last’, Unique’, ‘Skip’, and ‘Index’ parameters. Select-Object also supports optimization where is it stops processing once its reach selection criterion.
Select-Object Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 12 |
## Select-Object ## [-InputObject ## [[-Property] ## [-ExcludeProperty ## [-ExpandProperty ## [-Unique] ## [-Last ## [-First ## [-Index ## [-Skip ## [-Wait] ## [ |
Select-Object Cmdlet Argument List:
- –ExcludeProperty: Specifies the properties that this cmdlet excludes from the operation.
- –ExpandProperty: Specifies a property to select, and indicates that an attempt should be made to expand that property.
- –First: Specifies the number of objects to select from the beginning of an array of input objects.
- –Index: Selects objects from an array based on their index values.
- –InputObject: Specifies objects to send to the cmdlet through the pipeline.
- –Last: Specifies the number of objects to select from the end of an array of input objects.
- –Property: Specifies the properties to select. These properties are added as NoteProperty members to the output objects.
- –Skip: Skips (does not select) the specified number of items.
- –SkipLast: Skips (does not select) the specified number of items from the end of the list or array.
- –Unique: Specifies that if a subset of the input objects has identical properties and values, only a single member of the subset will be selected.
- –Wait: Indicates that the cmdlet turns off optimization.
PowerShell Select-Object Cmdlet:
Get All Objects Available In A Cmdlet For Selection In PowerShell:
1 2 3 4 5 6 7 8 |
######################################### ## PowerShell | Cmdlet | Select-Object ## ######################################### ## PowerShell Latest Version (5) ## get all objects available in a cmdlet for selection Get-Process | Get-Member -MemberType Properties |
Select Specific Objects From A Cmdlet Output In PowerShell:
1 2 3 |
## select specific objects in the output Get-Process | Select-Object Id, Name, WorkingSet64 |
Select Top 10 Rows From The Output In PowerShell:
1 2 3 |
## get the top 10 rows in the output Get-Process | Select-Object -First 10 |
Select Bottom 10 Rows From The Output In PowerShell:
1 2 3 |
## get the bottom 10 rows in the output Get-Process | Select-Object -Last 10 |
Skip First 100 Rows From The Output In PowerShell:
1 2 3 |
## skip 1st 100 rows in the output Get-Process | Select-Object -Skip 100 |
Select Unique Data In The Output Of PowerShell:
1 2 3 |
## get only unique data in the output Get-Process | Select-Object Name -Unique |
Get Extended Property Of An Object In PowerShell:
1 2 3 4 5 |
## get extended property of an object in PowerShell Get-Process | Select-Object Modules -First 10 Get-Process | Select-Object -ExpandProperty Modules -ErrorAction SilentlyContinue | Select-Object -First 10 |
Hope you have enjoyed this article. In the next blog post, we will discuss Group-Object cmdlet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation