开发者

Powershell: Join path issues with copy item

开发者 https://www.devze.com 2023-03-15 08:13 出处:网络
I have the following piece of code: $ServerPath = \\\\test\\ps $fullpath = Join-Path $ServerPath \"\\stackoverflow\"

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:\'
0

精彩评论

暂无评论...
验证码 换一张
取 消