---
title: "Understanding PowerShell EQ Operators"
description: "Master the EQ, NE, CEQ, and CNE PowerShell comparison operators. A tutorial by a PowerShell MVP."
canonical: "https://adamtheautomator.com/powershell-eq/"
---

# Understanding PowerShell EQ Operators

> Master the EQ, NE, CEQ, and CNE PowerShell comparison operators. A tutorial by a PowerShell MVP.

Source: https://adamtheautomator.com/powershell-eq/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Understanding PowerShell EQ Operators](https://adamtheautomator.com/wp-content/uploads/2019/06/5d238ae5c824b514689ea5af.jpg)

# Understanding PowerShell EQ Operators

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)30 June 20192 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

Table of Contents

*   [PowerShell -EQ and -CEQ](#-eq-and-ceq)
*   [\-NE and -CNE](#-ne-and-cne)

Are you struggling with understanding PowerShell comparison operators like `eq`, `ne`, `ceq` and `cne`. If so, read on.

Coming from a software development background the first instance I had a “Huh?” moment was when I first saw PowerShell’s comparison operators `eq`, `ceq`, `cne`, etc. All other languages have comparison operators but not quite like PowerShell. I was used to `==` and `<>`.

Not only does the syntax look completely different than your typical programming language they also behave differently when dealing comparing collections of values.

It’s something that really hung me up when learning about [PowerShell](https://adamtheautomator.com/tag/powershell/) but now it seems like that ol’ beer adage; it’s an acquired taste.

Let’s go over briefly what a comparison operator is if you’re unfamiliar and dive deeper into the nuances that PowerShell introduces. Before long, you’ll be able to wield operators in your PowerShell scripts with no problem.

As I mentioned, all programming/scripting languages have comparison operators. In their most basic sense, comparison operators are necessary to evaluate how different things compare to other things. They are used to take two objects and see what the difference (if any) is between those two objects.

In PowerShell’s case, operators can also be used to find elements inside collections of values.

For this post, I’m going to go over the equality operators and how PowerShell uses them. These are `eq` and `ne` with their case-sensitive counterparts `ceq` and `cne`. For a full list you can hop over the the [Technet site](http://technet.microsoft.com/en-us/library/hh847759.aspx) or just use `Get-Help about_comparison_operators`in your Powershell console.

## PowerShell -EQ and -CEQ

If you ever need to see if an object is equal to another object you have to use the `eq` (case-insensitive) or `ceq` (case sensitive) operators. These operators test the value of each entity you’d like to compare against.

When I first started learning PowerShell I’d constantly do something like this

```powershell
$string = 'Adam'
if ($string = 'Adam') {
    'string is equal to Adam'
}
```

You’ll soon be smacked enough to not do that. The `=` sign is an assignment operator NOT a comparison operator. You cannot use the `=` sign to compare one value against another.

The proper way to do this is to define the value to check on the left side of the expression and use the `eq` operator. Here’s an example of the `eq` and `ceq` operators and how they’re used.

![PowerShell's eq vs ceq](https://adamtheautomator.com/content/images/2019/07/powershell-eq-ne-ceq-cne---image-16.png)

PowerShell’s eq vs ceq

Notice how `eq` returned a boolean `True` value when comparing our variable against `adam` but `ceq` returned a boolean `False` value? This displays the case sensitivity difference between the two operators.

This is all well and good for scalar (single) values but you can also find all instances of particular values using these operators as well. For example, use the PowerShell -eq operator to filter items in an array:

![Using Eq to search arrays](https://adamtheautomator.com/content/images/2019/07/powershell-eq-ne-ceq-cne---image-17.png)

Using Eq to search arrays

If you’ve got a variable with a collection of values such as an array you can use `eq` and `ceq` to find all instances of values inside the collection.

Notice that it found all of the instances of the integer 9 we tried to compare against. I use this handy method all the time.

## \-NE and -CNE

On the opposite side, you’ve both `ne` and `cne`. They are exactly the opposite of `eq` and `ceq` but display the exact same behavior only opposite. They don’t test equality, they test inequality.

![PowerShells ne vs. cne](https://adamtheautomator.com/content/images/2019/07/powershell-eq-ne-ceq-cne---image-18.png)

PowerShells ne vs. cne

I hope this gives a good explanation of the equality comparison operators. This really got me hung up as a newbie and it never really clicked for me until I was just beat into submission by error messages. I hope this post prevents the same beat down I received.

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-eq%2F&text=Understanding%20PowerShell%20EQ%20Operators)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-eq%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-eq%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
