Selecting and sorting
Select-Object allows a subset of data to be returned when executing a command. This may be a more restrictive number of elements, or a smaller number of properties.
Sort-Object can be used to perform both simple and complex sorting.
The Select-Object command
Select-Object is most frequently used to limit values by a command. The command is extremely versatile as it enables you to do the following:
- Limit the properties returned by a command by name:
Get-Process | Select-Object -Property Name, Id- Limit the properties returned from a command using wildcards:
Get-Process | Select-Object -Property Name, *Memory- List everything but a few properties:
Get-Process | Select-Object -Property * -Exclude *Memory*- Get the first few objects:
Get-ChildItem C:\ -Recurse | Select-Object -First 2- Get the last few objects:
Get-ChildItem C:\ | Select-Object -Last 3- Skip items at the beginning. In this example, this returns the fifth item:
Get-ChildItem C:\ | Select-Object -Skip 4 -First 1- Skip...