How can I follow a windows shortcut in power shell?
You may add this to your Microsoft.PowerShell_profile.ps1
file. The cd
command will then work as desired.
remove-item alias:cd -force
function cd($target)
{
if($target.EndsWith(".lnk"))
{
$sh = new-object -com wscript.shell
$fullpath = resolve-path $target
$targetpath = $sh.CreateShortcut($fullpath).TargetPath
set-location $targetpath
}
else {
set-location $target
}
}
Unfortunately, Windows does not make it easy to work with shortcuts. This should work:
$sh = New-Object -COM WScript.Shell
cd $sh.CreateShortcut('your-files-here.lnk').TargetPath