Strange behavior with the Get-Alias cmdlet

Does anyone know why the following command treats the dollar sign as a wildcard instead of a literal:

Get-Alias -Name ?

Is there a way to use an escape character to treat the dollar sign as a literal in the previous command? It causes all aliases that have a name with a single character to be returned instead of only the alias “?” (Where-Object).

Expected behavior would be the same as the following:

Get-Alias | Where-Object Name -eq ?

Just something I ran into and wanted to see what others thought about this.

Escape it using a back tick. The cmdlet doesn’t have a -LiteralName parameter.

Same results using the back tick to escape it:

Get-Alias -Name `?

Looks like internally, the Name parameter of Get-Alias must do a “like” match on the value entered as the following returns the same results:

Get-Alias | Where-Object Name -like ?

Sweet. The new code formatter works awesomely.

Even the back ticks work in the new code formatter :slight_smile:

Clicking the “Preformatted” button once is all that’s needed which results in “pre]{content}[/pre” being added. I replaced the content including the curly braces with my code. A common mistake might be trying to click the button before and after your code like the old code formatter.

Based on responses from @SystematicADM that I received on Twitter, both of the following work so these are ways to escape the wildcard searching and search for the literal question mark without having to resort to piping to Where-Object.

Get-Alias -Name ``?
Get-Alias -Name '`?'

When you need to escape one of the special characters in the usual “like” wildcards, you can place them in square brackets. (I didn’t know about embedding a backtick in the string as well, which seems to work). You could also use Get-ChildItem on the alias:\ drive, which does have a -LiteralPath parameter:

Get-Alias [?]
Get-ChildItem -LiteralPath Alias:\?

Thanks Dave! That gives me a number of options depending on the particular scenario.