Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

-contains and -like answer different questions in PowerShell. Use -contains to test whether a collection has an exact value; use -like to match text against a wildcard pattern. For example, 'PowerShell' -like '*shell' is $true, while 'PowerShell' -contains 'shell' is $false.

What each operator does

The practical distinction is membership versus pattern matching:

  • -contains asks whether the left-hand collection contains an element equal to the right-hand value.
  • -like asks whether the left-hand string fits a wildcard expression on the right.

They are not interchangeable. -contains does not search for a substring, and -like is not an exact collection-membership test.

Syntax and return values

-contains: collection on the left

<Collection> -contains <scalar-object>

Containment operators always return one Boolean value: $true or $false. They stop once a matching element is found.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
$names = @('Ada', 'Grace', 'Linus')
$names -contains 'Grace'   # $true
$names -contains 'grace'   # $true (ordinary form is case-insensitive)
$names -contains 'Alan'    # $false

The comparison is against whole elements. With $names, the value 'ra' is not an element, so it is not a match even though those characters occur inside 'Grace'.

-like: string and wildcard expression

<string> -like <wildcard-expression>

With a scalar left operand, -like returns a Boolean:

'PowerShell' -like '*shell'      # $true
'PowerShell' -like 'Power?hell'   # $true
'PowerShell' -like 'Power'        # $false

The pattern must describe the complete value unless wildcards allow additional characters. A leading or trailing * is therefore commonly used for “contains this text” or prefix/suffix checks.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Choosing the right operator

Need Expression Meaning and result
Check exact membership @('abc','def') -contains 'def' $true, because def is an element.
Match a suffix 'PowerShell' -like '*shell' $true; * can match the prefix.
Match one character 'PowerShell' -like 'Power?hell' $true; ? matches one character.
Require exact scalar equality $value -eq 'PowerShell' Use equality when no wildcard pattern is needed.
Use the same membership test with reversed operands 'def' -in @('abc','def') The -in form asks whether the left scalar is in the right collection.

If your question is “Is this exact value one of these items?”, use -contains (or -in). If it is “Does this text fit this pattern?”, use -like. For exact comparison of two scalar values, use -eq.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What happens when the left side is a collection?

PowerShell comparison operators do not all produce the same shape of output when the left operand is an array.

Containment remains Boolean

@('app.log', 'app.txt') -contains 'app.log'
# $true

-contains, -notcontains, -in, and -notin always produce a single Boolean, even when the input is a collection.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

-like filters and returns matching members

@('app.log', 'app.txt', 'readme.md') -like '*.log'
# app.log

When -like receives a collection on the left, PowerShell applies the pattern to each element and returns the matching members (as strings), not one overall $true or $false. If nothing matches, the result is no output (an empty result), which is different from a Boolean $false.

This behavior also applies to other comparison operators such as -eq: do not assume that every comparison against an array is a true/false test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Case sensitivity

The ordinary string comparison forms are case-insensitive. Their explicit prefixes make the intent clear:

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
  • -contains and -like are case-insensitive by default.
  • Use -ccontains or -clike for case-sensitive comparison.
  • Use -icontains or -ilike when you want to state case-insensitivity explicitly.
'PowerShell' -clike '*shell'  # $false
'PowerShell' -clike '*Shell'  # $true
@('Admin','admin') -ccontains 'admin' # $true (matches only lowercase element)

The c and i prefixes are useful in shared scripts because they document whether capitalization is significant instead of relying on the default.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

PowerShell wildcard rules for -like

-like uses PowerShell wildcard syntax, not regular expressions:

  • * matches zero or more characters.
  • ? matches exactly one character.
  • [ ] specifies character alternatives or ranges.
'cat' -like 'c[ab]t'   # $true
'file7' -like 'file[0-9]' # $true

Matching a wildcard literally

Escape a wildcard character with a backtick when the character itself must be present in the text:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
'100% complete *' -like '*`*'  # $true: the final asterisk is literal

Use a string literal for the right-hand pattern when possible. An expandable double-quoted string can interpolate variables before PowerShell interprets the wildcard expression, which may change the pattern you intended.

Common mistakes and fixes

Using -contains for a substring

'PowerShell' -contains 'shell'  # $false

The left operand is a scalar string here, and -contains is asking for collection membership rather than searching inside the text. For a substring-style test, use a wildcard:

'PowerShell' -like '*shell*'     # $true

Reversing -contains

'def' -contains @('abc','def')   # not the intended membership form

Write the collection first:

@('abc','def') -contains 'def'

Or use the reversed-operand operator:

'def' -in @('abc','def')

Expecting a Boolean from collection filtering

This expression returns matching values:

$matches = @('error.log','notes.txt') -like '*.log'

To turn that into an explicit existence test, test the result as a collection:

$matches.Count -gt 0

Alternatively, use -contains when you already know the exact filename you need to find.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Using regex syntax with -like

Wildcard patterns and regular expressions are different languages. Patterns for -like use *, ?, and bracket expressions. Use -match when you specifically need a regular expression.

Practical decision checklist

  • Is the left side a collection and the right side an exact item? Use -contains.
  • Is the value text that must fit a wildcard pattern? Use -like.
  • Is the left side an array and do you want matching elements returned? Use collection input with -like.
  • Do you need one Boolean answer for collection membership? Use -contains or -in.
  • Does capitalization matter? Choose the c-prefixed form; use the i-prefixed form to make insensitive behavior explicit.
  • Is the comparison exact scalar equality? Use -eq.
  • Do you need regex features rather than wildcards? Use -match.

Version and documentation scope

Microsoft’s comparison-operator reference for Windows PowerShell 5.1 and its PowerShell 7.x language and tutorial documentation describe this same core distinction. Details around the operators’ surrounding language behavior can vary by installed version, so check the documentation for the PowerShell version running your script when relying on a version-specific edge case.

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.