我有一个简单的备份脚本,可以将 Documents 文件夹复制到外部硬盘:
Copy-Item C:\Users\Username\Documents G:\Backup -Recurse -Force
但是,当我运行该命令时,Windows 8 为文件夹'...\Documents\My Music'
、'...\Documents\My Pictures'
和'...\Documents\My Videos'
. 但是,这些文件夹只是符号链接,我认为这是导致错误的原因。如何避免复制符号链接?
编辑:即使使用硬编码的排除列表也不起作用。完整脚本如下:
$backupFolder = (get-date -uformat %Y%m%d)
$lines = Get-Content backup.cfg
$DirLinks = "C:\Users\Me\Documents\My Videos", "C:\Users\Me\Documents\My Music","C:\Users\Me\Documents\My Pictures"
$basePath = $lines[0] + $backupFolder + "\"
for ($i = 1; $i -lt $lines.Length; $i++)
{
$lines[$i]
Copy-Item $lines[$i] ($basePath + ($lines[$i].Replace(":", ""))) -Recurse -Force -Exclude $DirLinks
}
"Done!"
我仍然收到以下错误:
Copy-Item : Access to the path 'C:\Users\Me\Documents\My Music' is denied.
At C:\Users\Me\Desktop\backup app\backup.ps1:20 char:5
+ Copy-Item $lines[$i] ($basePath + ($lines[$i].Replace(":", ""))) -Recurse -F ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (My Music:DirectoryInfo) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CopyDirectoryInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
Copy-Item : Access to the path 'C:\Users\Me\Documents\My Pictures' is denied.
At C:\Users\Me\Desktop\backup app\backup.ps1:20 char:5
+ Copy-Item $lines[$i] ($basePath + ($lines[$i].Replace(":", ""))) -Recurse -F ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (My Pictures:DirectoryInfo) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CopyDirectoryInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
Copy-Item : Access to the path 'C:\Users\Me\Documents\My Videos' is denied.
At C:\Users\Me\Desktop\backup app\backup.ps1:20 char:5
+ Copy-Item $lines[$i] ($basePath + ($lines[$i].Replace(":", ""))) -Recurse -F ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (My Videos:DirectoryInfo) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : CopyDirectoryInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand