Problem
You want to use a cmdlet that supports wildcarding but provide a filename that includes wildcard characters.
Solution
To prevent PowerShell from treating those characters as wildcard characters, use the cmdlet’s –LiteralPath (or similarly named) parameter if it defines one: GetChildItem LiteralPath '[My File].txt'
Discussion
One consequence of PowerShell’s advanced wildcard support is that the square brackets used to specify character ranges sometimes conflict with actual filenames. Consider the following example:
PS >GetChildItem | SelectObject Name
Name
[My File].txt
PS >GetChildItem '[My File].txt' | SelectObject Name PS >GetChildItem LiteralPath '[My File].txt' | SelectObject Name
Name
[My File].txt
The first command clearly demonstrates that we have a file called [My File].txt. When we try to retrieve it (passing its name to the GetChildItem cmdlet), we see no results. Since square brackets are wildcard characters in PowerShell (like * and ?), the text we provided turns into a search expression rather than a filename.
The –LiteralPath parameter (or a similarly named parameter in other cmdlets) tells PowerShell that the filename is named exactly—not a wildcard search term.
In addition to wildcard matching, filenames may sometimes run afoul of another topic—PowerShell escape sequences. For example, the backtick character (`)in PowerShell means the start of an escape sequence, such as `t (tab), `n (newline), or `a (alarm). To prevent PowerShell from interpreting a backtick as an escape sequence, surround that string in single quotes instead of double quotes.
For more information about the GetChildItem cmdlet, type GetHelp GetChildItem.
For more information about PowerShell’s special characters, type GetHelp About_ Special_Characters.