# Variable in the file’s name filter.

**URL:** <https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269>\
**Category:** PowerShell Help\
**Created:** [February 18, 2014, 8:11am UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269 "2014-02-18T08:11:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stan-gor](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@stan-gor](https://forums.powershell.org/u/stan-gor)\
**Post date:** [February 18, 2014, 8:11am UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269/1 "2014-02-18T08:11:10Z")

</div>

Hello!

I am new to PowerShell scripting your help will be really appreciated!

The following works for me by running it as .ps1 script:

```
$source="C:\Backup\Full\"
Get-ChildItem $source -Recurse -filter "aaa_bbb_client_FULL.txt"
```

The following does not work for me by running it as .ps1 script:

```
$client="sclient"
$source="C:\Backup\Full\"
Get-ChildItem $source -Recurse -filter "aaa_bbb_" + $client + "_FULL.txt"
```

error I am getting:  
Get-ChildItem : A positional parameter cannot be found that accepts argument '+  
'.

Please help me to understand what I am missing.

Regards

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [February 18, 2014, 8:12am UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269/2 "2014-02-18T08:12:55Z")

</div>

well, you’ve put “sclient” into the second example, whereas the first used “client”. But, you don’t need to concatenate:

`
Get-ChildItem $source -Recurse -filter “aaa_bbb_$($client)_FULL.txt”
`

Ought to give the same result.

---

<div class="post-metadata">

**Author:** ![richard-siddaway](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@richard-siddaway](https://forums.powershell.org/u/richard-siddaway)\
**Post date:** [February 18, 2014, 8:14am UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269/3 "2014-02-18T08:14:51Z")

</div>

Try  
Get-ChildItem $source -Recurse -filter “aaa\_bbb\_$client\_FULL.txt”

or

Get-ChildItem $source -Recurse -filter (“aaa\_bbb\_” + $client + “\_FULL.txt”)

Filter expects a single string to define the filter criteria. Using + (concatenation) it only looks at the first string and treats the rest as different parameters

---

<div class="post-metadata">

**Author:** ![stan-gor](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@stan-gor](https://forums.powershell.org/u/stan-gor)\
**Post date:** [February 18, 2014, 8:16am UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269/4 "2014-02-18T08:16:22Z")

</div>

Thank you so much for your help!!! It worked.

PS

Sorry for typo

---

<div class="post-metadata">

**Author:** ![stan-gor](https://avatars.discourse-cdn.com/v4/letter/s/90ced4/32.png) [@stan-gor](https://forums.powershell.org/u/stan-gor)\
**Post date:** [February 18, 2014, 8:19am UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269/5 "2014-02-18T08:19:41Z")

</div>

The following worked!!!

```
Get-ChildItem $source -Recurse -filter “aaa_bbb_$($client)_FULL.txt”
```

---

<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:52pm UTC](https://forums.powershell.org/t/variable-in-the-file-s-name-filter/2269/6 "2024-05-16T20:52:25Z")

</div>


