You do a lot of Filtering output in PowerShell, primarily using the Where-Object cmdlet. This blog post will show you a few ways to do that. And that you shouldn’t use the “old” method when filtering only one property 😉

The old and new methods with one filter
I often see Where-Object used in the old “method” when filtering just one property. This is a method that was valid until PowerShell v3.0.
The syntax was:
C:\Users\HarmVeenstra> Get-ChildItem | Where-Object {$_.Name -match "Update"} Directory: C:\Users\HarmVeenstra
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 5-11-2023 19:37 101 update.ps1The new syntax from PowerShell v3.0 and higher is:
C:\Users\HarmVeenstra> Get-ChildItem | Where-Object Name -match "Update" Directory: C:\Users\HarmVeenstra Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 5-11-2023 19:37 101 update.ps1
I’m struggling with a PowerShell Where clause with an array that contains wildcards. Here’s the command in my much larger code,
$excludedOUs = @("*OU=Loaners,*", "*OU=InStock,*", "*OU=Conference Room,*","*OU=Training,*")
Get-ADComputer -SearchBase $targetOU -Property LastLogonDate,LastLogon | Where-Object { $_.DistinguishedName -notin $excludedOUs } | Select-Object Name,DistinguishedName, @{l='LastLogonDate';e={[DateTime]::FromFileTime($_.LastLogon)}}$excludedOUs = @("Loaners", "InStock", "Conference Room", "Training")I would prefer it. But, I need to use the wildcards because the sub-OU is only a part of the DistinguishedName property. Additionally, the array may not always be limited to just these four items. It might be a single item, or none, or dozens. I won’t know how others in the organization will use this. Any suggestions are appreciated.
When retrieving data with PowerShell you often only need a part of it. This is where the PowerShell Where Object cmdlet comes in. It allows you to select only the objects that you need from the results.
Good to know is that there is a big difference between using the -Filter parameter of a cmdlet and piping the Where-Object cmdlet behind it. Both can filter the results, but there is a big difference between them.
In this article
In this article, we will take a look at how to use the PowerShell Where-Object cmdlet and explain what the difference is with the Filter parameter.
The comparison statement is easier to read and write when you only want to filter the result on a single statement.
Get-Service | Where-Object -Property Status -eq "Running"
We can even minimize this further if you want, but I don’t recommend it because it will make your scripts harder to read:
Get-Service | Where Status -eq "Running" # Or even: Get-Service | ? Status -eq "Running"
Get-Service | Where-Object {$_.Status -eq "Running"}
Get-Service | Where-Object {($_.Status -ne "Running") -and ($_.StartType -eq 'Automatic')}You can find all possible comparison operators here in this article.

If you’ve ever found yourself needing to filter data in PowerShell, then you’ve likely encountered the powerful Where-Object cmdlet. This versatile cmdlet, often just called Where, allows you to filter objects based on their properties. You can use this cmdlet to filter out objects based on specified conditions, enabling you to quickly narrow down your results and focus on the relevant information.
The Where-Object cmdlet is a versatile and flexible tool in PowerShell, allowing you to filter data using various techniques. This article will provide an in-depth analysis of these techniques and show you how to use them effectively to enhance your PowerShell skills. We will cover the basic syntax and usage of Where-Object, advanced filtering with multiple conditions, using comparison operators, implementing wildcards and regular expressions, and combining techniques for precise results.
In this guide, you’ll learn:
- What is Where-Object, and why is it useful?
- Filtering collections with simple property comparisons
- Using operators like -eq, -ne, -gt, -lt etc.
- Leveraging -like and -notlike for wildcard filtering
- Using the -is and -isnot operators to check the type of an object.
- Matching on regular expressions with -match and -notmatch
- Combining multiple filters with -and and -or
- Filtering based on object types, dates, times, and more
- Case-sensitive filtering with -ccontains and -cmatch
- Filtering nested properties and calculated values
Are you confused and unable to know whether you should use the Where-Object or the Select-Object in PowerShell? In this PowerShell tutorial, I will explain the differences between PowerShell where-object vs. select-object and when you should use which one.
What is Where-Object in PowerShell?
The Where-Object cmdlet in PowerShell is used to filter objects based on their property values. It allows you to pass through objects that meet certain criteria and exclude those that do not. Essentially, Where-Object is a filtering tool.
For example, if you want to find processes that are consuming more than 50MB of memory, you could use Where-Object like this:
Get-Process | Where-Object { $_.WS -gt 50MB }What is Select-Object in PowerShell?
On the other hand, Select-Object is used to select specific properties of an object or a set of objects. It can also be used to create new calculated properties or to select a unique or specific number of objects from a collection.
For instance, if you want to display only the name and ID of all processes, you could use Select-Object like this:
Get-Process | Select-Object Name, IdThis command will output a table with just the Name and Id properties of each process.
Examples of Where-Object and Select-Object in Use
Let’s consider a real-world scenario where you might need to use both Where-Object and Select-Object in PowerShell. Suppose you need to retrieve a list of currently running services and display their name and status. Here’s how you could do this by using the below PowerShell script.
Get-Service | Where-Object { $_.Status -eq 'Running' } | Select-Object Name, StatusIn this pipeline, Get-Service retrieves all services, Where-Object filters only the services that are running, and Select-Object selects the Name and Status properties to be displayed.
Differences Between PowerShell Where-Object and Select-Object
Now, let’s summarize the differences between these two cmdlets: PowerShell Where-Object and Select-Object.

| Feature | Where-Object | Select-Object |
|---|---|---|
| Purpose | Filters objects based on property values | Selects specific properties of objects |
| Usage | To include/exclude objects in the pipeline | To manipulate or display object properties |
| Example | Get-Process | Where-Object { $_.CPU -gt 10 } | Get-Process | Select-Object Name, CPU |
| Output | Objects that meet the criteria | Objects with only the selected properties |
| Flexibility | Used for comparison operations | Used for property selection and manipulation |
Conclusion
Where-Object and Select-Object are two distinct cmdlets in PowerShell with different purposes. Where-Object is a filter that allows you to specify conditions to include or exclude objects in the pipeline, whereas Select-Object is used to select specific properties from objects or to create new calculated properties.
I hope now you know the differences between PowerShell Where-Object and Select-Object cmdlets and you know where to use Where-Object and where to use the Select-Object in PowerShell.
You may also like:
Two of the most commonly used filtering techniques in PowerShell are Where-Object, and the filter keyword in function definitions. In this PowerShell tutorial, I will explain everything about the PowerShell Where-Object vs Filter.
In PowerShell, Where-Object is a cmdlet used for filtering objects based on specified criteria within a pipeline, allowing for complex expressions. On the other hand, the filter keyword defines a function that acts as a dedicated filter, which can be more efficient for repeated use. Where-Object is more versatile for inline, ad-hoc filtering, while filter is better for scenarios where a specific, reusable filter is beneficial.
Example of Where-Object
Get-Process | Where-Object { $_.CPU -gt 100 }This command retrieves all processes with a CPU usage greater than 100. The $_ represents each object that comes through the pipeline, which in this case is each process.
PowerShell Filter in Function Definitions
The filter keyword in PowerShell is used to define a function that inherently acts as a filter. Functions defined using filter are designed to process input from the pipeline just like Where-Object, but they are generally more concise and can be more efficient in certain scenarios.
Example of Filter
filter HighCPUUsage { if ($_.CPU -gt 100) { $_ } }
Get-Process | HighCPUUsageThis defines a filter function named HighCPUUsage that filters processes with CPU usage greater than 100, similar to the Where-Object example.
Comparing Where-Object and Filter in PowerShell
While both Where-Object and filter serve similar purposes, they have differences in syntax, performance, and use cases. Let’s explore these differences in detail.
Differences in Syntax
Differences in Performance
Differences in Use Cases
Where-Object is versatile and can be used for one-off, complex filtering directly within a pipeline. filter functions are better suited for scenarios where the same filtering logic needs to be reused across multiple scripts or sessions.
PowerShell Where-Object vs Filter
Here are the complete differences of PowerShell Where-Object vs Filter.
| Feature | Where-Object | Filter Function |
|---|---|---|
| Definition | Cmdlet | Keyword to define a function |
| Syntax | Inline script block or comparison statement | Named function that can be reused |
| Performance | Can be slower due to runtime interpretation | Generally faster due to compilation |
| Reusability | One-off use in pipelines | Can be reused across scripts and sessions |
| Complexity | Supports complex logic | Best used for simpler, more focused filtering logic |
| Versatility | Highly versatile, can be used with any cmdlet | Limited to the defined function, not universally applicable |
| Pipeline Input Processing | Processes each object in the pipeline | Processes each object in the pipeline |
| Customizability | Highly customizable with script blocks | Customizable within the function definition |
| Ease of Use | Simple for quick, one-time filters but can get complex for advanced filtering | Simple and clean for defining reusable filters, but requires understanding of function definitions |
Example of PowerShell Where-Object vs Filter
Now, let us understand with an example of where to use the PowerShell Where-Object Vs Filter.
Suppose you want to filter event logs for events with an ID of 1000.
Using Where-Object
Get-EventLog -LogName Application | Where-Object { $_.EventID -eq 1000 }This command retrieves all application event logs with an EventID of 1000.
Using Filter
filter EventIDFilter { if ($_.EventID -eq 1000) { $_ } }
Get-EventLog -LogName Application | EventIDFilterThis defines a filter function EventIDFilter that you can use to retrieve the same event logs.

Conclusion
Both Where-Object and filter are very useful cmdlets in PowerShell. Where-Object is flexible and powerful for inline filtering, while filter functions provide a clean and potentially more performant way to apply filters, especially when the same logic is needed repeatedly.
I hope now you understand whether you choose Where-Object or filter, both while managing and manipulating data within PowerShell. Leave your thoughts on PowerShell Where-Object vs Filter in the comments.
You may also like:
Filtering Nested Properties
You can filter on nested object properties using dot notation. You can also chain properties:
Get-ADUser -Filter * | Where-Object {$_.Enabled -and $_.Manager.Name -like "*Smith"}Here is another example of filtering Windows Event Log by EventID:
# Fetching application log events with EventID 1001
$Events = Get-EventLog -LogName Application | Where-Object { $_.EventID -eq 1001 }
# Displaying the first 5 results
$Events | Select-Object -First 5How to Filter with Regular Expressions in PowerShell?
Regular expressions can be used in Windows PowerShell by using the -match, -notmatch, -replace, and other similar operators. Let’s learn how to filter using these operators within the Where-Object cmdlet, and apply filter data based on a pattern match or wildcard characters. E.g.,
Get-Process | Where-Object {$_.Name -match "^S.*"} | Select Name, IDHere, we use a regular expression and a match operator to filter input objects (processes in this case) based on their names. The script selects only the processes whose names start with the letter ‘S’.
What does Where-Object do?
“The Where-Object cmdlet selects objects that have particular property values from the collection of objects that are passed to it. For example, you can use the Where-Object cmdlet to select files that were created after a certain date, events with a particular ID, or computers that use a particular version of Windows.”
Wrapping Up
The Where-Object cmdlet in PowerShell allows you to easily filter the results, but keep the filter left principle in mind. Always use the filter or selection properties of the Get- cmdlet first, before using where object.
I hope you found this article helpful, if you have any questions, just drop a comment below.
Using PowerShell Where Command with the Property Parameter
Get-Service | Where-Object -Property StartType -Eq -Value Disabled
In the above example, we are filtering the services based on their StartType property using the property parameter. Only the services with a StartType of ‘Disabled’ will be selected.
Here is another example of filtering based on the property value of an object:
Get-ChildItem C:\Temp -File | Where Length -gt 1MB

Let’s find all files with .txt extension using PowerShell:
Get-ChildItem -Path C:\Docs | Where-Object { $_.Extension -eq ".txt" }Case-Sensitive Matching in Where Object Command
By default, the PowerShell where object command filtering is not case-sensitive. Use -cmatch and -ccontains for case-sensitive comparisons:
"John","Sarah","JAKE","john" | Where-Object {$_ -ccontains "john"}This will match the string “john” from the given array. For case-sensitive regular expressions, use:
Get-service | Where-Object {$_.Name -cmatch "^[a-z]"}Now, only names starting with a lowercase letter will match.
Filtering Objects based on their types with IS and ISNOT operators
in PowerShell, the -is and -isnot operators are used to check the type of object. Here are quick examples demonstrating how to use these operators with the Where-Object cmdlet, which is often abbreviated as Where.
# Create an array with different types of objects
$items = 42, "hello", 64, [DateTime]::Now, 100
# Use the -is operator to filter out only integers
$items | Where-Object { $_ -is [int] }Similarly, use the -isnot operator to filter out everything that is not a specific type (E.g., string)
$items | Where-Object { $_ -isnot [string] }Using comparison operators in the Where-Object filter
PowerShell uses several comparison operators that you can use for filtering data, including equality operators, matching operators, Containment Operators, etc.
| Operator | Description |
|---|---|
| Eq / Ne | Equal to / Not equal to |
| Gt / Ge | Greater than / Greater than or equal to |
| Lt / Le | Less than / Less than or equal to |
| Like / NotLike | Matches a pattern using wildcards / Does not match a pattern using wildcard characters |
| Match / NotMatch | String matches regex pattern / Does not match a pattern using regular expressions |
| Contains / NotContains | Contains a substring / Does not contain a substring |
| In / NotIn | Used to check whether a specified value exists in a set of values / Not exists in the set of values |
| Ceq / Cne / Cmatch / CNotMatch / Clike / CNotLike / CContains / Cin/Cnotin | Case-sensitive equal to/not-equal to/match/Notmatch/like/Not-like/contains/in/Not-in |
| Cge / Cgt/ Clt / Cle | Case-sensitive greater than or equal to, Greater than, Less than, Less than or equal to |
These operators allow you to create complex filtering conditions for your Where-Object cmdlet, giving you greater control over the data you work with in PowerShell. More on Comparison Operators in PowerShell is here! PowerShell Comparison Operators: An Essential Guide
Here is a simple example with Get-Service cmdlet, which returns a list of computer services. With the PowerShell where-object cmdlet, we can filter the list to return only services that have a specific property, such as:
Get-Service | Where-Object { $_.Status -eq "Running" }In this example, we filtered the list to return all services in the “Running” state. The $_.status property checks whether a service is running or stopped, and we used the -eq (equals) operator to return only those services that have the status property set to “Running”.
How to use the PowerShell Where-Object cmdlet for Wildcard Filtering?
To enable wildcard searches, use the PowerShell operators -like and -notlike.
Get-Command | Where-Object { $_.Verb -Like "Get*" }$Names = "Alex", "Jane", "Andrew", "Emily"
$FilteredNames = $Names | Where-Object { $_ -like "A*"}The below example filter processes that contain “Chrome” in their name:
Get-Process | where {$_.Name -contains "Chrome"} Using the Where-Object command with PSObject in PowerShell
Let’s walk through a simple real-world scenario using Where-Object with PSCustomObject in PowerShell. Say you have a list of employees. You want to find all employees who earn more than a specific threshold.
# Creating a list of employees as PSCustomObjects
$Employees = @( [PSCustomObject]@{Name="Alice"; Position="Developer"; Salary=75000}, [PSCustomObject]@{Name="Bob"; Position="Designer"; Salary=60000}, [PSCustomObject]@{Name="Charlie"; Position="Manager"; Salary=85000}, [PSCustomObject]@{Name="David"; Position="Developer"; Salary=68000}
)
# Filtering employees with a salary greater than 65000
$HighEarners = $Employees | Where-Object { $_.Salary -gt 65000 }
# Displaying the high earners
$HighEarners | Format-Table -Property Name, Position, Salary
Filtering Calculated Values
Where-Object filters don’t have to be static values. You can perform calculations. Let’s use PowerShell to find all the files in a specific directory that were created within the past 30 days:
Get-ChildItem -Path C:\Temp -File |
Where-Object { $_.CreationTime -gt (Get-Date).AddDays(-30) } |
Select-Object Name, CreationTimeIn this script, We calculate the threshold date, which is 30 days from the current date, and then filter the results with Where-Object based on the CreationTime property.
Troubleshooting common errors in PowerShell filtering
When working with PowerShell filters, you may encounter some common errors. Here are some tips for troubleshooting these errors:
- Incorrect use of comparison operators: Ensure you are using the correct comparison operator for your filter condition. For example, use
-eqfor equality and-gtfor greater than. - Syntax errors in script blocks: Make sure your script block statement is enclosed in curly braces (
{}) and that your conditions are properly formed. - Incorrect property names: Ensure you are using the correct property names for the objects you are filtering. You can use the
Get-Membercmdlet to view the properties of an object.
Best Practices for Efficient Filtering
- Filter as early as possible in the command to limit the number of results passed through the pipeline.
- Utilize filterable parameters provided by cmdlets whenever possible.
- Use specific properties to filter objects effectively.
- Take advantage of comparison operators and regular expressions for flexible filtering.
- Use aliases like ‘Where’ for brevity and easier readability.
- Combine filters using logical operators such as -and, -or, -xor to create more complex conditions.
- Minimize the use of the pipeline: Each time you use the pipeline, PowerShell has to do a bit of extra work, marshaling the objects and unmarshaling them on the other end
- Use -Filter parameter When available: Use cmdlets with the -Filter parameter instead of Where-Object. This will do the filtering right at the source, which can dramatically improve performance. E.g., Get-ADUser
Using Where-Object with multiple conditions
C:\Temp> Get-ChildItem | Where-Object {($_.Name -match "Untitled" -and $_.Name -match "png") -and $_.LastWriteTime -lt (Get-Date).AddDays(-120)} Directory: C:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 23-9-2021 23:06 16008812 Untitled.4png.png
-a--- 5-10-2021 23:33 45190 Untitled1.png
-a--- 16-6-2022 21:28 1582520 Untitled23123.png
-a--- 9-6-2022 20:23 19832 Untitled4.pngIt retrieved four files in total. Without the extra filter on the LastWriteTime property, it would show these six files in total:
C:\Temp> Get-ChildItem | Where-Object {$_.Name -match "Untitled" -and $_.Name -match "png"} Directory: C:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 23-9-2021 23:06 16008812 Untitled.4png.png
-a--- 10-12-2023 21:25 9936 Untitled.png
-a--- 5-10-2021 23:33 45190 Untitled1.png
-a--- 5-10-2023 11:13 360114 Untitled2.png
-a--- 16-6-2022 21:28 1582520 Untitled23123.png
-a--- 9-6-2022 20:23 19832 Untitled4.pngWhere-Object vs Filter
Get-ADUser -Filter * | Where-Object {($_.Name -like 'Zoe *') -and ($_.Title -eq "Fixer")}If the cmdlet supports it, always use the Filter or Name parameter. This is also known as the “Filter left” principle, which emphasizes on filtering as far left as possible:
Get-Aduser -filter {name -like 'Zoe *'} -properties title | Where-Object {$_.Title -eq "Fixer"}Filtering with Multiple comparison operators
Get-ChildItem -Path 'C:\Temp' -Include '*.jpg', '*.mov' -Recurse | Where-Object {$_.Length -gt 10MB -and $_.LastWriteTime -gt (Get-Date).AddDays(-10)}This command recursively searches the C:\ drive for .jpg and .mov files and filters them based on size and modification date. Here is another example of using a where clause with date values:
Get-ChildItem | Where-Object {$_.CreationTime -gt [datetime]"01/01/2022"}Using Where-Object with multiple filters
In the example above, only one property was filtered for something specific (In the example, I searched for any file in the current directory that has an update in its filename). But what if you want to filter on multiple properties?
Filtering for all files with “update” in its name and with the “.ps1” file extension:
C:\Users\HarmVeenstra> Get-ChildItem | Where-Object {$_.Name -match "Update" -and $_.Name -match "ps1"} Directory: C:\Users\HarmVeenstra
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 5-11-2023 19:37 101 update.ps1Filtering for all files with “update” in their name or with the “.ps1” file extension will also show files with update in their name.
C:\Users\HarmVeenstra> Get-ChildItem | Where-Object {$_.Name -match "Update" -or $_.Name -match "ps1"} Directory: C:\Users\HarmVeenstra
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 12-1-2024 16:56 0 test.ps1
-a--- 12-1-2024 16:53 0 testupdate.txt
-a--- 5-11-2023 19:37 101 update.ps1The #1 reason you shouldn’t use it for
I wrote it in a blog post a while back here, but you should always try to filter as much data as possible before letting Where-Object filter the returned data. It’s just faster!
Understanding Where-Object Filtering Techniques in PowerShell
Basic PowerShell Where-Object syntax and usage
Get-Command | Where-Object {<filter script>}<Command-That-Produces-Output> | Where-Object { $_.<PropertyName> -<Operator> <Value> }
Let’s go through a simple example where we have a list of numbers, and we want to filter out only the even numbers using Where-Object in PowerShell.
$Numbers = 1..100
$EvenNumbers = $Numbers | Where-Object { $_ % 2 -eq 0 }In the above example, We have first created a range of numbers from 1 to 100 using $numbers = 1..100. We then filter the even numbers by piping the $numbers array into Where-Object. The condition $_ % 2 -eq 0 checks if a number is even. ($_ represents the current number being processed in the pipeline.)
Get-Service | Where-Object {$_.Status -eq 'Running'}In this example, the $_ automatic variable represents the current object in the pipeline. We have used the comparison statement -eq that checks if the Status property of the current object is equal to 'Running'. If it is, the object is included in the output. In short, the where condition used in this PowerShell filters the output.

PowerShell also provides shorthand aliases and syntax for some of these cmdlets. For Where-Object, you can use ? as an alias:
Get-Service | ? { $_.Status -eq "Running" }This example returns objects that satisfy the particular property value. In this case, filter services with running status.
Where-Object Examples
We have taken a look at the basics of how to use the Where-Object cmdlet in PowerShell. I can explain each operator in detail, but it is easier to understand with the help of examples. So let’s take a look at a couple of examples of how to use the where object cmdlet:
Filtering by Value
Values are basically a property of an object. For example, to get all the files that are larger than 1MB, we can use the Get-ChildItem cmdlet and select only the objects where the property length greater is than 1MB:
Get-ChildItem -Path C:\Temp -Recurse | Where-Object {$_.Length -gt 1MB}Filtering on multiple values
Sometimes you want to select the results based on multiple values. You could use multiple -and statements for this. But that will make your code harder to read and maintain. A better option is to use an array and check if the properties are in the array.
$fruitsWanted = @("Apple", "Grapes", "Kiwi", "Strawberry", "Watermelon")
$fruitsAvailable = @("Apple", "Banana", "Orange", "Grapes", "Mango", "Strawberry", "Pineapple", "Watermelon", "Kiwi", "Pear")
$fruitsAvailable | Where-Object {$_ -in $fruitsWanted}Or the other way around with the contain operator:
$fruitsAvailable | Where-Object {$fruitsWanted -contains $_}Now this is a simple example, but you can also use this method with nested properties of course.
Using Regular Expressions
Get-service | Where-Object {$_.name -match "^p\d"}Filtering by Dates
Another common method is to filter the results based on a date. For example when you want to get all the files that are created in the last 7 days. To do this we will use the greater than operator and a date object:
Get-ChildItem -path c:\temp | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-7)}Filtering with multiple conditions in Script Block
You can use the Where-Object PowerShell cmdlet to filter results based on multiple conditions. To do this, you can use logical operators such as -and, -or, and -not to combine your conditions. Here is an example of using multiple conditions to filter the results of the Get-Process cmdlet:
Get-Process | Where-Object {$_.WorkingSet -gt 10MB -and $_.CPU -gt 300}In this example, we are filtering the results to display only processes with a working set greater than 10MB and a CPU time greater than 300 seconds. The -gt operator is a comparison operator that checks if the specified property is greater than the given value.
Get-Service | Where-Object -FilterScript {$_.Status -eq 'Stopped' -and $_.StartType -eq 'manual'}Conclusion
In conclusion, you can use the Where-Object script in PowerShell to find the items you need with great accuracy. It lets you filter results to find specific elements rather than showing everything in a list. By learning the syntax, comparison operators, and advanced filtering techniques, you can get the exact information you want.
Whether you are working with files, services, or processes, the Where-Object cmdlet is your best tool for filtering data in PowerShell. Remember, practice makes perfect. Try different filtering examples, learn advanced options, use best practices, and become good at using the Where-Object cmdlet. Happy scripting!
What is Where-Object In PowerShell?
Where-Object is a cmdlet in PowerShell that allows you to filter objects from a collection based on specific criteria. It is used to select objects that meet certain conditions and discard the rest. This cmdlet is commonly used in PowerShell scripts and commands to manipulate and filter data.
Can I use Where-Object with other cmdlets?
Yes, you can use Where-Object with other cmdlets to selectively filter and process objects in the PowerShell Pipeline. You can combine this versatile cmdlet with various others to accomplish specific tasks.
How can I negate a filtering condition in Where-Object?
Can I use Where-Object to filter arrays or collections?
Yes, you can use Where-Object to filter arrays or collections of objects. You can pipe an array or collection to Where-Object and specify the filtering conditions based on the properties of the objects in the array or collection.
How do I remove duplicates from an object in PowerShell?
What is the alias for where-object in PowerShell?
How do I find the property of an object in PowerShell?
How to check object type in PowerShell?
How to use the PowerShell where-object is not null?
How do I use multiple conditions in Where-Object
PowerShell Select-Object and Where-Object
Sometimes, you may want to filter a dataset and then select specific properties of the filtered objects to display. To achieve this, you can use the Select-Object cmdlet in combination with the Where-Object cmdlet in PowerShell scripts.
Here is an example of how to use PowerShell Where-Object and Select-Object cmdlets to retrieve a list of running services and display their name and status:
Get-Service | Where-Object {$_.Status -eq 'Running'} | Select-Object Name, StatusIn this example, the first command Get-Service retrieves a list of services, which is then filtered by the second command Where-Object to display only running services. Finally, the Select-Object cmdlet is then used to select the Name and Status properties of the filtered objects.


