Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesUse -contains to ask whether a collection includes an exact value; use -like to test a string against a wildcard pattern. They solve different problems: -contains is a membership check, while -like is a pattern match.
What is the difference between -contains and -like?
-contains checks whether the collection on its left includes the value on its right and returns $true or $false. -like compares a string on its left with a wildcard expression on its right.
As an Amazon Associate I earn from qualifying purchases.
For example, 'PowerShell' -like '*shell' is true because the wildcard can match the characters before shell. But 'PowerShell' -contains 'shell' is false: the left operand is not a collection containing an element equal to shell. Microsoft documents these operators in its comparison-operator reference.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →When should you use each operator?
Use -contains for exact collection membership
Put the collection on the left and the value to look for on the right. The question is: “Is this value one of the collection’s elements?”
#1 Best Overall
@('abc', 'def') -contains 'def'
This returns $true because def is an element. The operand order matters: -contains is not an infix operator for checking whether text contains a substring.
You can express the same membership question with -in and reverse the operands: 'def' -in @('abc', 'def').
Rank #2
Use -like for wildcard string patterns
Put the string on the left and a wildcard expression on the right. The question is: “Does this string fit this text pattern?”
'PowerShell' -like '*shell'
This returns $true because * can match a sequence of characters. If you need exact scalar string equality rather than a pattern, use -eq.
Rank #3
What do the wildcard characters mean?
PowerShell wildcard patterns are not regular expressions. The main wildcard characters are:
*matches a sequence of characters, including an empty sequence.?matches one character.[ ]can specify character alternatives or ranges.
For example, 'PowerShell' -like 'Power?hell' is true because the question mark matches one character. To match a wildcard character literally in a pattern, escape it with a backtick. Microsoft’s wildcard reference describes the pattern syntax and recommends using a string literal for the right-hand pattern; expandable strings can interpolate content before wildcard parsing.
Rank #4
- Book - powershell for sysadmins: workflow automation made easy
- Language: english
- Binding: paperback
How do results change when the left operand is a collection?
Do not assume every comparison operator returns one Boolean when its left operand is a collection. The output depends on the operator:
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute-containsalways returns a Boolean and stops after finding a match.-likefilters a collection and returns the matching members as strings. It does not return one overall Boolean for the collection.
This distinction is especially useful in scripts: use -contains when you need a yes-or-no membership answer, and use -like when you want the items whose text matches a pattern. Microsoft’s comparison-operator reference documents this collection behavior.
Best Value
Are these operators case-sensitive?
The ordinary string-comparison forms are case-insensitive. Add c after the hyphen to make the comparison case-sensitive, or use i to make case-insensitivity explicit:
-containsand-icontainsare case-insensitive;-ccontainsis case-sensitive.-likeand-ilikeare case-insensitive;-clikeis case-sensitive.
For example, 'PowerShell' -clike '*shell' performs case-sensitive wildcard matching. The PowerShell language specification says the ordinary -<operator> form is equivalent to the -i<operator> form for these string comparisons.
Which one should you choose?
| Need | Example | What it checks |
|---|---|---|
| Check exact collection membership | @('abc','def') -contains 'def' |
Whether def is an element; returns a Boolean. |
| Match a suffix pattern | 'PowerShell' -like '*shell' |
Whether the string ends in shell, with any prefix. |
| Match one character | 'PowerShell' -like 'Power?hell' |
Whether one character fits the position marked by ?. |
| Make wildcard matching case-sensitive | 'PowerShell' -clike '*shell' |
Whether the string matches the wildcard pattern with case respected. |
The basic distinction is covered by Microsoft’s comparison reference for Windows PowerShell 5.1 and its PowerShell 7.6 comparison tutorial; the wildcard and language-specification references are for PowerShell 7.5. Check documentation for the PowerShell version you use if you are investigating version-specific behavior.
Recommended Free Tools
For a general overview of comparisons, see Microsoft’s comparison-operator reference and PowerShell 101 comparison tutorial.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




