PowerShell is a powerful scripting language and command-line shell designed especially for system administration. One of its most versatile and widely-used cmdlets is Select-Object. This cmdlet is essential for filtering and selecting specific properties from objects, making it invaluable for managing data in scripts and automation tasks. In this blog post, you’ll dive deep into Select-Object, exploring its various features and practical applications.
Understanding Select-Object
The Select-Object cmdlet allows you to select specific properties of an object or set of objects. This can be particularly useful when dealing with large datasets or when you only need a subset of information from an object.
Basic Syntax:
Select-Object
[-InputObject <PSObject>]
[[-Property] <Object[]>]
[-ExcludeProperty <String[]>]
[-ExpandProperty <String>]
[-Unique]
[-CaseInsensitive]
[-Last <Int32>]
[-First <Int32>]
[-Skip <Int32>]
[-Wait]
[<CommonParameters>]
Let’s walk through some examples to see how Select-Object can be used in various scenarios.
- Start by opening your PowerShell console. You can do this by searching for PowerShell in your start menu and clicking on it.

- Run the following command to get a list of running processes:
Get-ProcessThis command gives you a comprehensive list of all running processes.

Selecting Specific Properties
To select specific properties from an object, you can use the -Property parameter. This is helpful when you want to narrow down the data to only the relevant fields.
- Now, use
Select-Objectto narrow down the data to just theName,Id, andCPUproperties.Get-Process | Select-Object -Property Name, Id, CPUThe
|character betweenGet-ProcessandSelect-Objectis the “pipe”. It passes the output fromGet-Processas the input forSelect-Object.
Excluding Properties
Sometimes, you might want to exclude certain properties from the output. The -ExcludeProperty parameter comes in handy in such cases.
- Use the following command to print the Name and peak metrics of a process using the Peak* wildcard:
Get-Process | Select-Object -Property Name, Peak* -First 1The
-First 1property will limit the output to the first process.
- Now, use the following command to exclude the properties PeakPagedMemorySize and PeakPagedMemorySize64 using the
-ExcludePropertywith the*Paged*wildcard:Get-Process | Select-Object -Property Name, Peak* -ExcludeProperty *Paged* -First 1
This will exclude all the properties with Paged in the name.
Expanding Properties
- The
-ExpandPropertyparameter allows you to expand a property that is an object in itself. This is useful when dealing with nested objects. Run the following command:Get-Service -Name "EventLog" | Select-Object -ExpandProperty DependentServicesThis command retrieves the
DependentServicesproperty of theEventLogservice and expands it, showing the details of the dependent services.
Removing Duplicates
- If you need to remove duplicate entries from your output, use the
-Uniqueparameter. Run the following PowerShell command and observe the output:Get-EventLog -LogName System | Select-Object Source -UniqueThis command retrieves the unique sources of events in the System event log.

Selecting the First or Last N Objects
- You can select the first or last N objects from the output using the
-Firstand-Lastparameters. Run the following commands and observe the output:Get-Process | Select-Object -First 5 Name, CPU Get-Process | Select-Object -Last 5 Name, CPUThese commands retrieve the first and last 5 processes, respectively, selecting the
NameandCPUproperties.
Skipping Objects
- To skip a specified number of objects and select the rest, use the
-Skipparameter. Run the following to skip the first 10 processes:Get-Process | Select-Object -Skip 10 Name, CPU
Practical Examples
- Listing Top CPU-Consuming Processes:
Get-Process | Sort-Object CPU -Descending | Select-Object -First 5 Name, CPUThis command sorts processes by CPU usage in descending order and selects the top 5.

- Extracting Event Log Information:
Get-EventLog -LogName Application | Select-Object EntryType, Source, Message -First 10This command retrieves the first 10 entries from the Application event log and selects specific properties.

Conclusion
The Select-Object cmdlet is a powerful tool in PowerShell for manipulating and selecting data. Whether you’re filtering process information, managing files, or working with event logs, understanding how to use Select-Object effectively can greatly enhance your scripting capabilities. By mastering its parameters and options, you can streamline your workflows and handle data more efficiently.
PowerShell’s versatility, combined with cmdlets like Select-Object, makes it an indispensable tool for system administrators and developers alike. Experiment with the examples provided and incorporate Select-Object into your daily tasks to see its full potential in action.
Discover more from Parveen Singh
Subscribe to get the latest posts sent to your email.