我有一些代码试图复制包含快捷方式的目录:
# Create a directory to store the files in
mkdir "D:\backup-temp\website.com files\"
# Search for shortcuts so that we can exclude them from the copy
$DirLinks = Get-ChildItem "\\web1\c$\Web Sites\website\" -Recurse | ? { $_.Attributes -like "*ReparsePoint*" } | % { $_.FullName }
# Execute the copy
cp -recurse -Exclude $DirLinks "\\web1\c$\Web Sites\website\*" "D:\backup-temp\website.com files\"
但是当我执行脚本时,我收到以下错误:
Copy-Item : The symbolic link cannot be followed because its type is disabled.
At C:\scripts\backup.ps1:16 char:3
+ cp <<<< -recurse "\\web1\c$\Web Sites\website\*" "D:\backup-temp\website.com files\"
+ CategoryInfo : NotSpecified: (:) [Copy-Item], IOException
+ FullyQualifiedErrorId :
System.IO.IOException,Microsoft.PowerShell.Commands.CopyItemCommand
似乎脚本挂起了一个符号链接(我假设快捷方式),我试图在脚本的第四行排除。
如何告诉powershell忽略/排除快捷方式?
谢谢, 布拉德
答案 0 :(得分:4)
如果您使用的是V3或更高版本,则可以消除重新分析点,如下所示:
Get-ChildItem "\\web1\c$\Web Sites\website" -Recurse -Attributes !ReparsePoint |
Copy-Item -Dest "D:\backup-temp\website.com files"
在V1 / V2上你可以这样做:
Get-ChildItem "\\web1\c$\Web Sites\website" |
Where {!($_.Attributes -bor [IO.FileAttributes]::ReparsePoint)} |
Copy-Item -Dest "D:\backup-temp\website.com files" -Recurse
答案 1 :(得分:0)
事实证明,我面临的问题在此Microsoft博客文章中有所解释: http://blogs.msdn.com/b/junfeng/archive/2012/05/07/the-symbolic-link-cannot-be-followed-because-its-type-is-disabled.aspx
基本上在服务器上运行PowerShell脚本我需要运行以下命令: fsutil行为集SymlinkEvaluation R2R:1
这允许Remote到远程符号链接。一旦到位,上面的powershell命令就会按预期运行而不会出现错误。