Author Posts

February 18, 2014 at 1:41 pm

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

February 18, 2014 at 1:42 pm

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.

February 18, 2014 at 1:44 pm

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

February 18, 2014 at 1:46 pm

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

PS

Sorry for typo

February 18, 2014 at 1:49 pm

The following worked!!!

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