# Wildcard-like syntax to call a function

**URL:** <https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021>\
**Category:** PowerShell Help\
**Created:** [November 28, 2022, 7:30am UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021 "2022-11-28T07:30:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![metablaster](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/metablaster/32/1224_2.png) [@metablaster](https://forums.powershell.org/u/metablaster)\
**Post date:** [November 28, 2022, 7:30am UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021/1 "2022-11-28T07:30:40Z")

</div>

I’ve stumbled upon the following syntax:

```powershell
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?

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 28, 2022, 8:58am UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021/2 "2022-11-28T08:58:24Z")

</div>

Did you try the command?

> [@metablaster](#):
>
> what do the square brackets do here

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

```auto
Get-Command [G]et-Process

```

… is the same like it is for

```auto
Get-Command Get-Process

```

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

```auto
Get-Command [GS]et-ItemProperty

```

😉  
The squere brackets are regex syntax for a character class.

> **[Regexp Tutorial - Character Classes or Character Sets](https://www.regular-expressions.info/charclass.html)**
>
> In a regular expression, square brackets are used to indicate character classes, which matches any of the characters in the character set.

---

<div class="post-metadata">

**Author:** ![metablaster](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/metablaster/32/1224_2.png) [@metablaster](https://forums.powershell.org/u/metablaster)\
**Post date:** [November 28, 2022, 9:13am UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021/3 "2022-11-28T09:13:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 28, 2022, 9:32am UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021/4 "2022-11-28T09:32:56Z")

</div>

> [@metablaster](#):
>
> You’re saying that we can regex almost any command instead of explicitly stating which command to run?

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

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

```auto
Get-Command -Name *et-ItemProperty

```

---

<div class="post-metadata">

**Author:** ![metablaster](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/metablaster/32/1224_2.png) [@metablaster](https://forums.powershell.org/u/metablaster)\
**Post date:** [November 28, 2022, 9:34am UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021/5 "2022-11-28T09:34:48Z")

</div>

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

Thank you a lot for explanation!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:16pm UTC](https://forums.powershell.org/t/wildcard-like-syntax-to-call-a-function/21021/6 "2024-05-16T20:16:17Z")

</div>


