---
title: "PowerShell Like Operator & More: Boost Your Scripting Game"
description: "Master the PowerShell like, match, and eq operators with real-world examples for single values and collections."
canonical: "https://adamtheautomator.com/powershell-like/"
---

# PowerShell Like Operator & More: Boost Your Scripting Game

> Master the PowerShell like, match, and eq operators with real-world examples for single values and collections.

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

---

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/)

![PowerShell Like Operator & More: Boost Your Scripting Game](https://adamtheautomator.com/wp-content/uploads/2020/04/scale-2635397_1280.jpg)

# PowerShell Like Operator & More: Boost Your Scripting Game

[![](https://secure.gravatar.com/avatar/c6d5f85f079bf60c80eadc9c4aafec44430609395a12821a3d3c31df47e32930?s=192&d=mm&r=g)Mohamed Mostafa](https://adamtheautomator.com/author/mohamedabdelbar/)2 July 20205 min. read

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

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

Table of Contents

*   [Testing for Equality With eq and ceq Operators](#testing-for-equality-with-eq-and-ceq-operators)
*   [Testing Case-Sensitivity With the ceq Operator](#testing-case-sensitivity-with-the-ceq-operator)
*   [Testing for Inequality With the ne and cne Operators](#testing-for-inequality-with-the-ne-and-cne-operators)
*   [Testing for Items in a Collection](#testing-for-items-in-a-collection)
*   [Testing Collections to Contain Values](#testing-collections-to-contain-values)
*   [Testing “Greater than” With gt and ge Operators](#testing-greater-than-with-gt-and-ge-operators)
*   [Testing “less than” With lt and le Operators](#testing-less-than-with-lt-and-le-operators)
*   [Matching Based on Wildcards with the PowerShell Like Operator](#matching-based-on-wildcards)
*   [Matching Based on Regular Expression](#matching-based-on-regular-expression)
*   [Summary](#summary)

Like many other programming languages, PowerShell has various comparison operators. However, unlike other languages, those comparison operators can look a little odd. Instead of `==`, you have `eq`. Instead of `<>`, you’ve got `ne`. It can be confusing to newcomers. Let’s check out the [PowerShell](https://adamtheautomator.com/powershell-eq/) like operator and other comparison operators in this article.

Related: [Understanding Powershell -Eq -Ne and More Comparison Operators](https://adamtheautomator.com/powershell-eq/)

## Testing for Equality With `eq` and `ceq` Operators

To check to see if one object is equal to another object in PowerShell is done using the `eq` operator. The `eq` operator compares simple objects of many types such as strings, boolean values, integers and so on. When used, the `eq` operator will either return a boolean `True` or `False` value depending on the result.

The `-eq` operator needs two values to compare. Let’s say you assign a string to a variable called `$string`. You’d like to compare this variable’s value to the string value `"PowerShell"` to ensure they are equal.

Related: [Concatenate, Expand, Format and All Things PowerShell Strings](https://adamtheautomator.com/powershell-strings/)

In the following example, you can see that we’re assigning the value `PowerShell` to the variable  `$string`. Then, using the `eq` operator, the example is comparing the value of `$string` with the string `powershell`.  Easy enough, right? But wait, they aren’t _really_ the same though.

```powershell
PS> $string = "PowerShell"
PS> $string -eq "powershell"
True
```

> _Note that `=` is an assignment operator and NOT a comparison operator. You cannot use `=` to compare one value against another in PowerShell._

## Testing Case-Sensitivity With the `ceq` Operator

In the above example, notice how `eq` returned a boolean `True` value above even when the string wasn’t the _exact_ same. This behavior happens because the `eq` operator is case-insensitive. To test for case-sensitive equality, use the `ceq` operator. The `ceq` operator is the exact same as `eq` with the exception of being case-sensitive.

You can see an example of using `ceq` in the following code snippet. Now notice the PowerShell sees the case-sensitive difference.

```powershell
PS> $string -ceq "PowerShell"
True 
PS> $string -ceq "powershell"
False
```

## Testing for Inequality With the `ne` and `cne` Operators

Just as `eq` and `ceq` test for _equality_, PowerShell has a pair of operators that do the exact opposite called `ne` and `cne`. Like their counterparts, these two operators perform the exact same operation yet opposite.

```powershell
PS> $string = "PowerShell"
PS> $string -ne "PowerShell"
False
PS> $string -cne "PowerShell"
False
PS> $string -cne "powershell"
True
```

## Testing for Items in a Collection

Typically, the `eq` and `ceq` operators are used for scalar or single values like strings, integers and boolean values. But these operators can also find instances of particular values contained within a collection like an array.

Notice in the example below that we’re creating an array with 12 integers. Perhaps you’d like to find all instances in that array that equal the number 9. No problem, use the `eq` operator against the array to return all instances of the compared integer.

```powershell
PS> $array =@(1,2,3,4,5,6,7,8,9,9,9,9)
PS> $array -eq 9
9
9
9
9
PS> ($array -eq 9).Count
4
```

## Testing Collections to Contain Values

Since you just learned about using the `eq` operator to find instances in arrays, let’s take that a step further and introduce the “containment” operators. These operators are `contains`, `notcontains`, `in` and `notin`. These operators return a boolean `True` or `False` value if a collection _contains_ an instance or not.

Check out the following example. In this example, we’re creating an array with nine integers. If you want a simple Yes/No answer to if that array contains a certain integer, you can get that using `contains` or `notcontains`.

```powershell
PS> $array = @(2,4,5,6,8,8,9,9,9)
PS> $array -contains 9
True
PS> $array -notcontains 9
False
PS> $array -contains 5
```

Similarly, you have the `in` and `notin` operators. These operators are nearly identical to `contains` and `notcontains` with one exception: the value to compare is on the left instead of the right.

```powershell
$array = @(2,4,5,6,8,8,9,9,9)
9 -in $array
True
9 -notin $array
False
```

## Testing “Greater than” With `gt` and `ge` Operators

What happens if you need to test whether a number (an integer) is _greater than_ another number or perhaps _greater than or equal to_ another number? You’d use the `gt` and `ge` operators. These operators compare integers.

Like the other operators, these operators return boolean `True` or `False` values depending on if one integer is greater than another. Both of these operators test whether the left integer is greater than or greater than or equal to the right integer.

In the below example, you can see how each of these operators behave.

```powershell
PS> 7 -gt 5
True
PS> 7 -gt 7
False
PS> 7 -ge 7
True
```

Similar to the `eq` operator that allows you to find instances in collections, you can do the same with the `ge` and `gt` operators too. PowerShell searches through each item in a collection and compares each value to the one you’ve provided. You can see a great example of this below.

```powershell
PS> $array =@(1,2,3,4,5,6,7,8,9,9,9,9)
PS> $array -gt 5
6
7
8
9
9
9
9
PS> $array -ge 5
5
6
7
8
9
9
9
9
```

## Testing “less than” With `lt` and `le` Operators

Similar to the `gt` and `ge` operators, the `lt` and `le` operators perform the same function yet opposite. The `lt` and `le` operators compare two values testing whether the integer on the left side is less than or less than or equal to the integer on the right.

You can see in the example below, the same functionality of comparing each value in a collection applies exactly the same as `gt` and `ge`.

```powershell
PS> $array =@(1,2,3,4,5,6,7,8,9,10)
PS> $array -lt 5
1
2
3
4
PS> $array -le 5 
1
2
3
4
5
```

## Matching Based on Wildcards with the PowerShell Like Operator

So far, you’ve learned how to perform 1:1 matches. All of the operators used so far compared one whole value against another but PowerShell has another trick up it’s sleeve. You can also compare values based on wildcards or asterisks.

Let’s say you only know a few characters of a string. You can’t use `eq` because `eq` requires you to know the entire string. Using the PowerShell like operator,  you don’t have to know the entire string. To test if a value is _like_ another, you can replace the part you don’t know with a wildcard.

As with other operators, this same functionality can be applied to collections too.

You can see an example of PowerShell like and it’s case-sensitive brother, `clike` below.

```powershell
PS> $string = "PowerShell"
PS> $string -like "*Shell"
True
PS> $array = @("PowerShell","Microsoft")
PS> $array -like "*Shell"
PowerShell
PS> $array -clike "*Shell"
PowerShell
```

The operator `-notlike` returns boolean `True` if no match found and `False` if there is a match. In case of using against a collection, it will return all other values that don’t match the pattern given on the right side of the `-notlike` operator. Adding case sensitivity to the pattern, use `-cnotlike` operator.

```powershell
$string = "PowerShell" 
$string -notlike "*Shell"
False
$array = @("PowerShell","Microsoft")
$array -notlike "*Shell"
Microsoft
$array -cnotlike "*shell"
PowerShell
Microsoft
```

## Matching Based on Regular Expression

The PowerShell like operator and its relative are handy but as soon as you begin to require more complex matching. At that point, you can dive into the deep, dark world of [regular expressions (regex)](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_regular_expressions?view=powershell-7.2&viewFallbackFrom=powershell-6). Using the `match` and `notmatch` operators, you can perform extremely complex string matching with regex.

Similar to the PowerShell like operator, `match` and it’s opposite counterpart, `notmatch`, compares two strings return a boolean `True` or `False` value. Also, like the other operators, the same behavior can be applied for a collection as the example below demonstrates.

```powershell
PS> $string = "PowerShell"
PS> $string -match "ow"
True 

PS> $array = @("PowerShell","Microsoft")
PS> $array -match "ow"
PowerShell

PS> $string = "PowerShell"
PS> $string -cmatch "po"
False
PS> $string -cmatch "Po"
True

PS> $array = @("PowerShell","Microsoft")
PS> $array -cmatch "Po"
PowerShell
```

## Summary

In this article, you learned about the PowerShell like operator and many others and how to use each operator for single values and collections. You’ve seen how the output differs based on the operator and whether scalar or collection.

Additionally, you’ve also seen operators with case sensitivity, matching operators how to match based on regular expression or wildcard, and containment operators to test if the object contains a specific value or if a value is existing in a specific object.

![powershell like](https://adamtheautomator.com/wp-content/uploads/2022/06/PowerShell-Like-1024x576.jpg)

PowerShell Like

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-like%2F&text=PowerShell%20Like%20Operator%20%26%20More%3A%20Boost%20Your%20Scripting%20Game)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-like%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-like%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/)
