The * wildcard will match zero or more characters

The ? wildcard will match a single character

[m-n] Match a range of characters from m to n, so [f-m]ake will match fake/jake/make

[abc] Match a set of characters a,b,c.., so [fm]ake will match fake/make

PowerShell wildcards are consistent in their meaning so using *.* will match any characters followed by a period (.) followed by any characters. In other words *.* will return only files that have an extension, not directories. To return all items just use a single *
This is quite different to the behaviour seen under the CMD shell.

When using WMI filters use the WMI specific wildcards: % for zero or more characters, _ for a single character.

Wildcards will also work within both single and double quotes, to prevent wildcard expansion use the -LiteralPath parameter where available.


PS C:\> Get-ChildItem c:\work\*.xls

PS C:\> Get-ChildItem c:\work\[a-f]*.txt

PS C:\> Get-ChildItem -literalpath 'c:\work\test[1].txt'

“We usually see only the things we are looking for, so much that we sometimes see them where they are not” ~ Eric Hoffer


Comparison operators -like, -lt, -gt, -eq, -ne, -match

© Copyright SS64.com 1999-2015
Some rights reserved