# Use Parentheses with Wildcard with Get-ChildItem

**URL:** <https://forums.powershell.org/t/use-parentheses-with-wildcard-with-get-childitem/23374>\
**Category:** PowerShell Help\
**Created:** [January 7, 2024, 12:55am UTC](https://forums.powershell.org/t/use-parentheses-with-wildcard-with-get-childitem/23374 "2024-01-07T00:55:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zero269](https://avatars.discourse-cdn.com/v4/letter/z/da6949/32.png) [@zero269](https://forums.powershell.org/u/zero269)\
**Post date:** [January 7, 2024, 12:55am UTC](https://forums.powershell.org/t/use-parentheses-with-wildcard-with-get-childitem/23374/1 "2024-01-07T00:55:34Z")

</div>

Hello,

I’m having some trouble figuring out how to use open and closing parentheses in a search string.

I’m currently running a test to find any folder with “**(59946)**” in the name. I’ll be using a variable for the numbered portion, but all are enclosed in parentheses once I get the parentheses to work in the search.

I’ve tried a few online suggestions for escaping special characters in a double-quoted string to no avail. I understand the backtick (`) is the escape character, and others have suggested using the backslash (\). However, neither yield any results:

```auto
$folder = '59946'
$folder = (Get-ChildItem -Path $srcPath -Include "*`($folder`)*" -Recurse -Directory
$folder = (Get-ChildItem -Path $srcPath -Include "*\($folder\)*" -Recurse -Directory
$folder = (Get-ChildItem -Path $srcPath -Include "`*`($folder`)`*" -Recurse -Directory

```

Ultimately I’ll be running this in a foreach loop to build a simple array. Something like this:

```auto
$quizList = Get-Content "$dstPath\list_current_week.txt"
Foreach ($quiz in $quizList) {
  $current_week = (Get-ChildItem -Path $srcPath -Include "`*`($quiz`)`*" -Recurse -Directory).Fullname
  $current_week =+ $current_week
}
$current_week

```

I can get a basic search to work if I build out the variable several times, but this doesn’t seem like the most effective/professional way of performing this kind of search.

```auto
$folder = '59946'
$folder = "(" + $folder + ")"
$folder = (Get-ChildItem -Path $srcPath -Include *$folder* -Recurse -Directory).Fullname

```

Results:

> Gateway Arch (Murray) (59946) - LG 3.1

Any help would be greatly appreciated…

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [January 7, 2024, 10:38am UTC](https://forums.powershell.org/t/use-parentheses-with-wildcard-with-get-childitem/23374/2 "2024-01-07T10:38:11Z")

</div>

Your last example is just building `"*(59946)*"` with no escape characters, and that should work fine:

```auto
PS E:\Temp\files> $srcPath = 'E:\Temp'
PS E:\Temp\files> $folder = 59946
PS E:\Temp\files> Get-ChildItem -Path $srcPath -Include "*($folder)*" -Recurse

    Directory: E:\Temp\Files\folder1

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 07/01/2024 10:33 Gateway Arch (Murray) (59946) - LG 3.1

```

---

<div class="post-metadata">

**Author:** ![zero269](https://avatars.discourse-cdn.com/v4/letter/z/da6949/32.png) [@zero269](https://forums.powershell.org/u/zero269)\
**Post date:** [January 11, 2024, 5:30am UTC](https://forums.powershell.org/t/use-parentheses-with-wildcard-with-get-childitem/23374/3 "2024-01-11T05:30:17Z")

</div>

Hello Matt,

You’re absolutely correct. I don’t know why I didn’t try this first without trying to escape those parentheses.  
I made the changes and ran it again:

```auto
$srcPath = '\\mynas\ar_quiz'
$folder = '59946'
(Get-ChildItem -Path $srcPath -Include "*($folder)*" -Recurse -Directory).Fullname

```

Returns: `\\mynas\ar_quiz\Gateway Arch (Murray) (59946) - LG 3.1`

Thanks again for your help Matt…

---

<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:** [January 11, 2024, 6:31am UTC](https://forums.powershell.org/t/use-parentheses-with-wildcard-with-get-childitem/23374/4 "2024-01-11T06:31:01Z")

</div>

Closed on January 11, 2024, 6:31am UTC


