Wildcard-like syntax to call a function

I’ve stumbled upon the following syntax:

Get-Command [G]et-CallerPreference -CommandType Function -Module PreferenceVariables

I have never seen a function called like this, what does it mean to say [G]et-CallerPreference what do the square brackets do here, what’s the behavior of this and how is this syntax called?

Did you try the command?

I’d say … Nothing at all. :wink: At least not if you only have one letter inside them. The output of … for example

Get-Command [G]et-Process

… is the same like it is for

Get-Command Get-Process

It’ll becomme another topic when you use it like this:

Get-Command [GS]et-ItemProperty

:wink:
The squere brackets are regex syntax for a character class.

1 Like

You’re saying that we can regex almost any command instead of explicitly stating which command to run?
Now that’s interesting, I wonder if there is official powershell documentation of this, not because I don’t believe you but because this is so unusual for a programing language.

Hmmmm … you noticed that the brakets belong to the parameter - not the actual command, don’t you? :wink:

To make that more obvious you could write it like this:

Get-Command -Name *et-ItemProperty
1 Like

Indeed, I woke up just recently so it could be that :grinning:

Thank you a lot for explanation!