Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
October 21, 2025

Going Wild with PowerShell

In this issue:

  • Wildcard Characters
  • Like vs Match
    • Case Sensitivity
    • NotLike
  • CIM Wildcard Queries
  • WildcardPattern
    • ToWql()
  • [SupportsWildCards]
  • Summary

A very common practice in PowerShell is the use of wildcards. We often use wildcards to limit results or fine-tune a search query. I thought it might be worthwhile to review how the different ways wildcards are used in PowerShell. These are concepts that might make PowerShell easier for you to use, or they might give you an idea of how to implement or support wildcards in your own scripts and functions.

Wildcard Characters

A wildcard pattern match is similar to a regular expression match. The former is much simpler and relies on only a few special characters which serve as placeholders. Where this might get confusing is that some of the characters can be used with a simple wildcard comparison or a more complex and structured regular expression comparison.

For a simple comparison using wildcards, the following characters have special meaning:

  • * - Matches zero or more characters.
  • % - Matches zero or more characters (used in SQL-like queries).
  • ? - Matches exactly one character.
  • [] - Matches any one character within the brackets.

You are most likely familiar with the * character. But you can also use comparison patterns like these:

  • "D[aeio]n"
  • "file-?.txt"
  • "wp*.jpg"
  • "p[wo]%"

I'll have examples of the other characters throughout this article.

Like vs Match

One critical element in a wildcard comparison is understanding the required operator. PowerShell has two operators that can be used for pattern matching: -like and -match. The former is used for simple wildcard comparisons, while the latter is used for regular expression comparisons. You need to ensure you are using the correct operator for your needs because the same pattern might give different results depending on which operator you use.

PS C:\> Get-Process | where name -like 'p[ow]*' | Measure | Select Count

Count
-----
   17

PS C:\> Get-Process | where name -match 'p[ow]*' | Measure | Select Count

Count
-----
   76

> This example is meant to illustrate the difference between -like and -match. It is not the best way to filter processes by name.

The -Like operator uses simple wildcard characters in the comparison string. If the comparison is true, PowerShell returns the object.

PS C:\> Get-Process -name p[ow]*

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    566      28    62156      27028       2.11   3592   0 powershell
    567      31    86596      58024     102.70  20376   0 powershell
   1523     100   436280     398612     237.19  20632   1 powershell
   1073     188   217036     372136      66.17  25948   1 pwsh
    862     107    95136     195512      23.77  38460   1 pwsh
   2176     227   658568     803216     182.22  38756   1 pwsh

The pattern is looking for process names that start with p followed by either o or w, followed by any number of characters. This comparison is case-insensitive. Here's the same command in Ubuntu.

PS /home/jeff> Get-Process P[ow]*

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
      0     0.00       7.50       0.47    2813 …13 polkitd
      0     0.00     163.84      21.91     951 730 pwsh

Here are some other examples.

PS C:\> 'PowerShell' -like '*shell'
True
PS C:\> 'PowerShell' -like '*well'
False
PS C:\> 'PowerShell' -like 'Power?hell'
True
PS C:\> 'PowerSShell' -like 'Power?hell'
False
PS C:\> 'PowerShell' -like 'Power[sh]ell'
False
PS C:\> 'Powerchell' -like 'Power[sc]hell'
True

It is important that you understand why the patterns fail or succeed.

Case Sensitivity

If you need a case-sensitive comparison, you can use the -cLike operator.

PS C:\> "don","Don","Jan","Dan","Din" -cLike "D[aeio]n"
Don
Dan
Din

One very nice feature of the -like operator is that it can accept arrays as input. This allows you to filter a list of strings easily without relying on Where-Object or ForEach-Object.

While it isn't used as much, you might come across the iLike operator. This is the same as -like and is explicitly case-insensitive.

PS C:\> "don","Don","Jan","Dan","Din" -iLike "D[aeio]n"
don
Don
Dan
Din
Want to read the full issue?
GitHub Bluesky LinkedIn Mastodon https://jdhitsoluti…
Powered by Buttondown, the easiest way to start and grow your newsletter.