Copy-Item doesn't work with square bracket in destination parameter

56 Views Asked by At

I am trying to copy a file from a folder to another using

Copy-Item  $source -Destination $destination

but in $destination I have square brackets: Copy-Item doesn't throw an error but doesn't copy too. It doesn't work if I replace square brackets with backtick (one or two backticks is the same)

if ($destination-match "\[") {
                $destination= $destination-replace "\[", "``["
            }
if ($destination-match "]") {
                $destination= $destination-replace "]", "``]"
            }

neither if I use

$destination = [Management.Automation.WildcardPattern]::Escape($path)

. Does anyone can help me?

Thanks in advance.

0

There are 0 best solutions below