Created
July 26, 2023 13:17
-
-
Save cxmeel/cd77525ea76e3942f3a142dc19fd1fd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Converts a Shortcut to a Symbolic Link. | |
# Place this somewhere on your PATH. | |
# | |
# Usage: | |
# $ to-symlink .\path-to-shortcut.lnk | |
# Converted ".\path-to-shortcut.lnk" to symlink. | |
$obj = New-Object -ComObject WScript.Shell | |
function Convert-ShortcutToSymlink { | |
param ( | |
[Parameter(Mandatory)] | |
[string]$ShortcutPath | |
) | |
if (!(Test-Path -Path $ShortcutPath)) { | |
Write-Error "Shortcut ""$ShortcutPath"" does not exist." | |
return | |
} | |
$shortcut = $obj.CreateShortcut($ShortcutPath) | |
$targetPath = $shortcut.TargetPath | |
$symlinkPath = $ShortcutPath -replace '\.lnk$' | |
New-Item -ItemType SymbolicLink -Path $symlinkPath -Target $targetPath -ErrorAction SilentlyContinue | Out-Null | |
Remove-Item $ShortcutPath | |
Write-Output "Converted ""$ShortcutPath"" to symlink." | |
} | |
Convert-ShortcutToSymlink -ShortcutPath $args[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment