Synchronizing shortcuts in Powershell
I have some code that tries to create a copy of a directory that 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 that the script is getting stuck on a symbolic link (I assume a shortcut) which I am trying to exclude in the fourth line of the script.
How can I tell powershell to ignore / exclude shortcuts?
Thanks, Brad
source to share
If you are on V3 or higher, you can exclude reparse points as follows:
Get-ChildItem "\\web1\c$\Web Sites\website" -Recurse -Attributes !ReparsePoint |
Copy-Item -Dest "D:\backup-temp\website.com files"
In 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
source to share
So it turns out that the problem I'm having is explained in this Microsoft Blog Post article: 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 run a powershell script from what I needed to run the following command: fsutil SymlinkEvaluation R2R feature set: 1
This allows remote symbolic links to be deleted. Once this is done, the above powershell commands run as expected without error.
source to share