Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell Copy-Item fails on User\Documents with Access Denied
    text
    copied!<p>I have a simple backup script to copy the Documents folder to an external hard drive:</p> <pre><code>Copy-Item C:\Users\Username\Documents G:\Backup -Recurse -Force </code></pre> <p>However, when I run the command, Windows 8 is raising an UnauthorizedAccessException for the folders <code>'...\Documents\My Music'</code>, <code>'...\Documents\My Pictures'</code>, and <code>'...\Documents\My Videos'</code>. However, these folders are just symbolic links, which I assume is what is causing the error. How can I avoid copying symbolic links?</p> <p><strong>Edit:</strong> Even using a hard-coded Exclude list does not work. Full script is below:</p> <pre><code>$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!" </code></pre> <p>I still get the following errors:</p> <pre><code> 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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload