Powershell: Join path issues with copy item
I have the following piece of code:
$ServerPath = \\test\ps
$fullpath = Join-Path $ServerPath "\stackoverflow"
Copy-Item $fullpath "c:\"
It gives me this output:
Cannot find path \test\ps\stackoverflow because it doesn't exist.
Inital \
character is omitted in full path when used with Copy-Item
command. but Write-Output
prints value correct开发者_运维问答ly.`
I want to join the path, someone please help me with this. Thanks in advance.
Be sure to use quotes when assigning a variable so that PowerShell does not try to execute the command
$ServerPath = '\\test\ps'
$fullpath = Join-Path $ServerPath '\stackoverflow'
Copy-Item $fullpath 'c:\'
精彩评论