我的脚本将目录(和所有子目录)复制到以今天的日期命名的新目录,再到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
答案 0 :(得分: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 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
)超出了错误消息中的限制。