Variable in the file’s name filter.


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

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

Get-ChildItem $source -Recurse -filter "aaa_bbb_client_FULL.txt"

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

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.


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.

Get-ChildItem $source -Recurse -filter “aaa_bbb_$client_FULL.txt”


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

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


Sorry for typo

The following worked!!!

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