Forum Discussion
jamesmcx
May 02, 2026Copper Contributor
Edit Windows Shortcut properties TargetPath and WorkingDirectory with a script?
I've moved data to a new drive, and there are a lot of shortcuts (*.lnk files) to different files in the data set. I'd like to create a script that edits the file paths in the shortcut properties "Ta...
May 10, 2026
The problem with the replace statement is that the $oldpath and $newpath contain backslashes. If you update it to this, it should work (Test it on a small set first ;-)
$lnk.TargetPath = $lnk.TargetPath -replace [regex]::Escape($oldPath), ($newPath)
$lnk.WorkingDirectory = $lnk.WorkingDirectory -replace [regex]::Escape($oldPath), ($newPath)