首页 > 解决方案 > 创建指向 UNC 路径的符号链接不起作用?

问题描述

我在获取符号链接以在 powershell 中工作时遇到问题,因为我无法在网络驱动器上创建文件夹。我尝试过Test-NetConnection -ComputerName crex2cloud -Port 445得到响应,但是当我尝试使用以下命令创建符号链接时;New-Item -ItemType SymbolicLink -path $pathh -Target $target它不起作用。
$pathh变量是并且$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

标签: powershell

解决方案


使用 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"

推荐阅读