EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell Where Object
 

PowerShell Where Object

Priya Pedamkar
Article byPriya Pedamkar

Updated March 24, 2023

PowerShell Where Object

 

 

Introduction to PowerShell Where Object

Where-Object allows us to select or get a particular object, file, process, services, etc. on the basis of certain properties of that object, file, process, services. These properties may be size, name, date, etc. Let me give you an example, suppose you have a folder containing 1000 files and you want to perform some task on the file which created most recently or the file which was created first. So We can select the file date wise. Another example, suppose we want to select the largest file among all file so we can put where the condition for the size of the file. We can also write conditions for getting information on any services, packages, processes, etc. In this topic, we are going to learn about PowerShell Where-Object.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

How to Create Where Object command in Powershell?

There are mainly two ways to create Where-Object command they are given below.

1. Script block

We can go with Script block to define property name, comparison operator and property value. The where-object command will check and return objects for which block is true.

Get-Process | Where-Object {comparison condition}

2. Comparison statement

In this way, we can directly use comparison like we use any normal programming.

Get-Process | Where-Object condition

Syntax:

A very simple way to get all syntax and parameters is to run the below command. All the given below syntax will be used in different kinds of situations. We will discuss some of them.

Get-Help Where-Object -full

PowerShell Where Object syntax

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] [-InputObject <psobject>] [-EQ] [<CommonParameters>]

Where-Object [-FilterScript] <Here we write script containing conditions> [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -GE [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CEQ [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -NE [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CNE [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -GT [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CGT [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -LT [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CLT [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CGE [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -LE [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CLE [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -Like [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CLike [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -NotLike [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CNotLike [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -Match [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CMatch [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -NotMatch [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CNotMatch [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -Contains [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CContains [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -NotContains [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CNotContains [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -In [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CIn [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -NotIn [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -CNotIn [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -Is [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> [[-Value] <Object>] -IsNot [-InputObject <psobject>] [<CommonParameters>]

Where-Object [-Property] <Property like date,size etc> -Not [-InputObject <psobject>] [<CommonParameters>]

Parameters of PowerShell Where Object

Here are the Parameters listed below.

1. CContains: It checks for if exact match, which means it will return an object only if the exact object match will work.

The general syntax for it is given below.

Get-Process | where servicename/processname/etc -CContains "exact matching name

2. CEQ: If the same property value is the same then only it gets the object

3. CGE: If the property value is greater than or equal to the passed value then only it gets the object.

4. CGT: If the property value is greater than the passed value then only it gets the object. Remember this condition is completely case-sensitive.

5. CIn: This will check for include, that is if property value include then it gets the object

6. CLE: This will check for less than or equal to the passed value.

7. CLT: This will check for less-than on passed value.

8. CLike: This will check for match property value, it also includes wildcards. Also, this operation is case sensitive.

9. CMatch: This property is based on regular expressions, So in where condition we can also check for with some regular expressions.

10. CNE: This command will be used with where condition if we are trying to find different then passed value.

11. CNotContains: It will get the object in case if the property value is not exactly matching to the passed value. This command condition is case sensitive.

Examples

Here are the Examples to implement PowerShell Where Object mention below

Example #1

In the below example we are checking services with the name “nginx” exact match. It returns all the running services with the name nginx. Please refer to the example along with the screen below.

Get-Process | where ProcessName -CContains "nginx"

PowerShell Where Object Example 1PowerShell Where Object Example 1

Example #2

In this command we are using -eq to get all match package with a specific version. First, we display all versions by running command Get-PackageProvider and than we searched for a specific version bypassing version exact in a script block.

Get-PackageProvider
Get-PackageProvider | Where-Object {$_.Version -eq "3.0.0.1"}
Get-PackageProvider | Where-Object {$_.Version -eq "2.1.3.0"}

PowerShell Where Object Example 2

Example #3

Here In this example, we wanted to know all the running processes with a name starting with “n”. In the output, we can see it is displaying “node nginx networkmanager netns, etc”. You can try it on your own system you will get different output according to running processes on your system with a name starting with “n”.This Where-object example is blocking script type.

Get-Process | Where-Object {$_.ProcessName -Match "^n.*"}

Example 3

Example #4

As we discussed at the time of introduction that there are two types of Where-Object, one is block script and another one is caparison. In example 3 we discussed block script, In this example, we are understanding caparison statement block.

Get-Process | Where-Object ProcessName -Match "^n.*"

Example 4

Conclusion

Where-Object used for fetching some object, files, process, services, etc. on the basis of certain conditions, these conditions may be property, name, size or date of the object, files, process, services.

Recommended Articles

This is a guide to PowerShell Where Object. Here we discuss the Parameters and Examples to implement  PowerShell Where Object. You may also have a look at the following articles to learn more –

  1. How to Use PowerShell?
  2. PowerShell Run Command
  3. Get-Command in PowerShell
  4. PowerShell Format Table | How to Format Table?

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - ENROLL NOW