首页 文章

Copy-Item出错:无法遵循符号链接,因为其类型已禁用

提问于
浏览
1

我的脚本将目录(和所有子目录)复制到以今天的日期命名的新目录到10个不同的服务器 .

$ServerList = Get-Content 'C:\Users\test\Powershellskript\testservrar.txt'
ForEach ($Server in $ServerList)
{
    $source = "\\$Server\C$\Java\testIX"
    $distanation = "\\$Server\C$\Backup"
    $today = (Get-Date).ToString('YY-MM-DD')
    $location = New-Item -Path $distanation -Type Directory -Name $today
    Copy-Item $source -Destination $location -recurse
}

但我得到以下两个错误,我该如何解决这个问题?

Copy-Item : The symbolic link cannot be followed because its type is disabled.
At C:\Users\baa065sa\Powershell skript\Untitled1.ps1:9 char:1
Copy-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
At C:\Users\baa065sa\Powershell skript\Untitled1.ps1:9 char:1

1 回答

  • 1

    您的第一个错误是因为默认情况下禁用 remote to remote symbolic links .

    您可以通过运行以下命令来检查(使用提升的命令提示符):

    fsutil behavior query SymlinkEvaluation
    

    然后将返回您的状态:

    Local to local symbolic links are enabled.
    Local to remote symbolic links are enabled.
    Remote to local symbolic links are disabled.
    Remote to remote symbolic links are disabled.
    

    并使用以下方法更改此行为

    fsutil behavior set SymlinkEvaluation R2R:1
    

    并再次查询以查看新状态:

    > fsutil behavior query SymlinkEvaluation
    
    Local to local symbolic links are enabled.
    Local to remote symbolic links are enabled.
    Remote to local symbolic links are disabled.
    Remote to remote symbolic links are enabled.
    

    你的第二个错误就像它说的那样:

    指定的路径,文件名或两者都太长 . 完全限定的文件名必须少于260个字符,目录名必须少于248个字符

    您的目标路径( \MyServerName\C$\Backup\Folder\Folder\...\file.txt )超出了错误消息中的限制 .

相关问题