创建指向UNC路径的符号链接不起作用?

时间:2020-06-09 04:44:30

标签: powershell

我无法在Powershell中使用符号链接,因为无法在网络驱动器上创建文件夹。我尝试Test-NetConnection -ComputerName crex2cloud -Port 445时得到响应,但是当我尝试使用以下命令创建符号链接时; New-Item -ItemType SymbolicLink -path $pathh -Target $target不起作用。
$pathh变量是 source $target是我要创建的目标文件夹,尽管每次我尝试使用上述命令创建符号链接时,都会出现此错误;

New-Item : Cannot find path 'T:\csync' because it does not exist.
At line:1 char:1
+ New-Item -ItemType SymbolicLink -path $pathh -Target $target

当我尝试使用UNC路径时,首先会有一个暂停;然后是这个错误;

New-Item : Cannot find path '\\crex2cloud\csync' because it does not exist.
At line:1 char:1
+ New-Item -ItemType SymbolicLink -path $pathh -Target $target

1 个答案:

答案 0 :(得分:0)

使用Test-Path代替Test-NetConnection

然后,您也可以将其包装在if语句中:

   if (Test-path '\\crex2cloud\csync') {Write-host "path found"}
    else
    {New-Item -ItemType SymbolicLink -path $pathh -Target $target}

还要仔细检查您对共享的权限。您也可以使用管理员共享。

"\\server\c$\whateverfolder"
相关问题