Skip to content

Instantly share code, notes, and snippets.

@nvnivs
Created November 6, 2015 13:49
Show Gist options
  • Save nvnivs/22c99bb55ef82127ffe6 to your computer and use it in GitHub Desktop.
Save nvnivs/22c99bb55ef82127ffe6 to your computer and use it in GitHub Desktop.
Create a junction path between two folders
# REMARK: By default UNC to local junctions are disabled
# To find out run 'fsutil behavior query SymlinkEvaluation'
# To enable run 'fsutil behavior set SymlinkEvaluation R2L:1'
$source = 'd:\folder-a'
$target = 'd:\folder-b'
Robocopy $source $target /MIR /R:12 /W:5
Invoke-Expression "cmd.exe /c attrib +r $source\\*.* /s"
Write-Host "Set source to read only"
Robocopy $source $target /MIR /R:12 /W:5
Write-Host "Moved source to $source-backup"
Move-Item $source "$source-backup" -ErrorAction Stop
Invoke-Expression "cmd.exe /c mklink /D $source $target"
Write-Host "Unset target read only"
Invoke-Expression "cmd.exe /c attrib -r $target\\*.* /s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment