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 recursing down through a file heirarchy, it is necessary to use the wildcard in an -include clause:
Get-ChildItem c:\windows -include *.exe -recurse

Writing the above like this will fail:
Get-ChildItem c:\windows\*.exe -recurse
the above will not match a file such as C:\windows\test\demo.exe

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


Regular Expressions - Search for a string.
Get-ChildItem - Get child items (contents of a folder or registry key)
Comparison operators -like, -lt, -gt, -eq, -ne, -match

Copyright © SS64.com 1999-2018
Some rights reserved