Reputation: 1015
I am trying to provide a path to Copy-Item cmdlet in Powershell which goes up few directories but I am getting error
"ERROR - failed with error: "A positional parameter cannot be found that accepts argument '......\'."
The command I am trying to execute is
Copy-Item $Source + "..\..\..\" + ($environment) + "\*.config" $destination
Can anyone please guide me how can I go up few directories while providing a path to Copy-Item
Upvotes: 0
Views: 57
Reputation: 1015
I just had to put double quotes around the whole path rather than concatenating.
Copy-Item "$Source\..\..\..\$environment\*.config" $destination
Upvotes: 0
Reputation: 58931
You need to parenthese the first argument (source):
Copy-Item ($Source + "..\..\..\" + ($environment) + "\*.config") $destination
Consider using the Join-Path cmdlet when combining a path. You could also write something like:
$sourceDir = Join-Path (Get-Item $Source).Parent.Parent.Parent $environment
Get-ChildItem -Path $sourceDir -Filter '*.config' | Copy-Item -Destination $destination
Upvotes: 3