3

I have some code which is trying to make a copy of a directory which contains shortcuts:

 # 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\"

But when I execute the script I get the following error:

 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

It seems the script is getting hung up on a symbolic link (I'm assuming the shortcut) that I'm trying to exclude in the fourth line of the script.

How can I tell powershell to ignore/exclude shortcuts?

Thanks, Brad

2
  • Which version of PowerShell? Commented Feb 2, 2014 at 21:51
  • Powershell version 2. Commented Feb 2, 2014 at 23:50

2 Answers 2

4

If you are on V3 or higher you can eliminate the reparse points like so:

Get-ChildItem "\\web1\c$\Web Sites\website" -Recurse -Attributes !ReparsePoint | 
    Copy-Item -Dest "D:\backup-temp\website.com files"

On V1/V2 you can do this:

Get-ChildItem "\\web1\c$\Web Sites\website" |
    Where {!($_.Attributes -bor [IO.FileAttributes]::ReparsePoint)} |
    Copy-Item -Dest "D:\backup-temp\website.com files" -Recurse
Sign up to request clarification or add additional context in comments.

6 Comments

I used the code for v1/v2 above and it seems to produce the same error: Get-ChildItem : The symbolic link cannot be followed because its type is disabled.
@Brad See if the updated answer helps any. With the recurse on the Get-ChildItem, it may have been trying to copy files under a ReparsePoint. Don't remember if those files would have that attribute set.
Removing -recurse seems to result in no error - but no files being copied either :)
Adding -ErrorAction SilentlyContinue seems to suppress the error and the code will work with -recurse. But I can't believe there isn't a better way of doing this?
Actually I lied. -ErrorAction SilentlyContinue allows the script to exit cleanly without an error but it does actually halt the file copy process. So that's not a viable option :(
|
1

So it turns out that the issue I faces is explained in this Microsoft Blog Post: http://blogs.msdn.com/b/junfeng/archive/2012/05/07/the-symbolic-link-cannot-be-followed-because-its-type-is-disabled.aspx

Essentially on the server I am running the powershell script from I needed to run the following command: fsutil behavior set SymlinkEvaluation R2R:1

This allows Remote to remote symbolic links. Once this is in place the above powershell commands run as expected without errors.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.