In this tutorial, I will explain how to work with the -First parameter of the PowerShell Select-Object cmdlet with some examples.
PowerShell Select-Object -First
The Select-Object cmdlet in PowerShell is used to select specific properties of an object or set of objects. It’s incredibly versatile, allowing you to filter and format data efficiently. One of its key features is the ability to select the first few objects from a collection using the -First parameter.
Syntax of PowerShell Select-Object -First
Here’s the basic syntax for Select-Object with the -First parameter:
Select-Object -First <Number>- -First: Specifies the number of objects to select from the beginning of the input.
The -First parameter is particularly useful when you need to quickly retrieve a subset of data from a larger dataset. For instance, if you have a list of users and you want to get the first five entries, Select-Object -First can accomplish this efficiently.
PowerShell Select-Object -First Examples
Now, let me show you some real examples of how Select-Object -First can be used in different scenarios.
Example 1: Select the First 5 Users
Imagine you have a list of users in your organization, and you want to get the first five entries. Here’s how you can do it:
Get-ADUser -Filter * | Select-Object -First 5This command retrieves all Active Directory users and then selects the first five users from the list. This can be particularly useful for auditing or reporting purposes.
Example 2: Retrieve the First 3 Files in a Directory
Suppose you need the first three files from a directory. The following command will help you achieve this:
Get-ChildItem -Path "C:\MyFolder" | Select-Object -First 3This command lists all files in the specified directory and selects the first three files. It’s a quick way to sample files from a directory.
I executed the above PowerShell script using VS code, and you can see the output in the screenshot below:

Check out PowerShell Select-Object Without Header
Example 3: Fetch the First 10 Processes
If you’re monitoring system performance and want to get the first ten processes, use the below PowerShell script with Select-Object -First parameter.
Get-Process | Select-Object -First 10This command lists all running processes and selects the first ten. It’s useful for getting a snapshot of the system’s state.
Example 4: Combine with Other Parameters
You can combine -First with other parameters like -Property to select specific properties of the first few objects. For example:
Get-Process | Select-Object -First 5 -Property Name, CPUThis command selects the first five processes and displays only their Name and CPU properties.
Here is the exact output in the screenshot below:

Read PowerShell Copy-Item
Example 5: Using with Where-Object
You can also use Select-Object -First in conjunction with Where-Object to filter data before selecting the first few objects. For example:
Get-Process | Where-Object { $_.CPU -gt 100 } | Select-Object -First 3This command filters processes with a CPU usage greater than 100 and then selects the first three.
Here is the exact output in the screenshot below:

Conclusion
In this tutorial, I explained how to use Select-Object -First in PowerShell. I have also provided a few real examples of PowerShell Select-Object -First parameter.
You may also like:
- PowerShell Write-Output
- PowerShell Write-Host vs Write-Error
- Get-ChildItem in PowerShell
- PowerShell Test-Path
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.