How to Change Shortcut (.lnk) Target in Bulk Using Script

Many users have shortcuts pointing to various network shares from other systems or your domain’s storage server. If your company migrates the server and changes the computer name, share name, or folder path, you need to manually update the shortcut targets to point to the right destination. In most cases, the folder structure may remain the same, but the server name usually changes.

For shortcuts pointing to a file or folder in the local machine, Windows updates the shortcuts automatically (using the “Distributed Link Tracking” service) when the target is moved or renamed. But, in the case of shortcuts pointing to network locations, they have to be done manually or using a program/script.

Updating the paths manually is tiring, especially if you have hundreds of shortcuts. This article has three methods to bulk update shortcut targets and/or arguments.

Change Shortcut (.lnk) Targets in Bulk

Pick one of the following options to bulk update shortcuts. Before proceeding, it’s advisable to backup the old shortcuts before the bulk update procedure, just in case you accidentally specify a wrong path in the utility or script file.

Option 1: Using the “Shortcut Search And Replace” tool

“Shortcut Search And Replace” from Jacquelin POTIER is an extremely useful utility that can bulk update shortcuts. It can update the shortcut target, arguments, as well as the working directory.

shortcuts search and replace bulk

This utility provides so many options, of which some are mentioned below:

  • Include the custom extra “Search Folder” for search and replace operations.
  • To include sub-directories, check the “Include subdirectories option”.
  • “Applies To”: Options to select which part of the shortcut is affected (multiple options can be checked)
    • Include shortcut target directory into search and replace operations. (Target file name not included, so you can change directory without affecting name). Note that this option also updates the working directory (if it matches.)
    • Include shortcut target file name into search and replace operations. (Target directory not affected)
    • Include shortcut icon directory into search and replace operations. (Target icon file name not included, so you can change icon directory without affecting icon name)
    • Include shortcut icon file name into search and replace operations. (Target icon directory not affected)
    • Include shortcut arguments into search and replace operations
    • Replace only the arguments matching the inputted target path (discard all other replace operations.)
    • Include comments in search and replace operations.

This tool has a command-line feature as well. For more information, read the .chm help file supplied with this tool. You can download ‘Shortcuts Search And Replace’ from the following link:

Option 2: Using VBScript

The following VBScript updates shortcuts containing a specified target path to the new target path. Also, it updates the old paths in shortcut arguments as well as the “Start in” directory.

How to Use:

  1. Save the above script to a permanent folder.
  2. Open the script using Notepad and edit the old path and new path accordingly in Line #27 and #28. Save the file and close it.
  3. Open your SendTo folder by running shell:sendto in Start/Run dialog.
  4. Place a shortcut to the above script in the SendTo folder and name it suitably — e.g., Update Shortcuts.
  5. Select one or more shortcuts you want to update, click Send To, and click “Update Shortcuts”.

That’s it. The script enumerates each shortcut, updates the paths accordingly, and outputs the result to a log file. Here’s a sample log:

bulk update shortcuts script - log file

Option 3: Using PowerShell

Here is a PowerShell script that automatically updates the shortcut target for .lnk files in a specified folder. This script automatically updates shortcuts that contain the old server name or path, replacing them with the new name or path.

Note: The following script doesn’t modify the old path name in arguments and the “Start in” directory.

$oldPrefix = "\\MEDIA"
$newPrefix = "\\MEDIA-PC"
$searchPath = "E:\Shortcuts"

$shell = new-object -com
write-host "Updating shortcut target" -foregroundcolor red -backgroundcolor black

dir $searchPath -filter *.lnk -recurse | foreach {
$lnk = $shell.createShortcut( $_.fullname )
$oldPath= $lnk.targetPath
$lnkRegex = "^" + [regex]::escape( $oldPrefix )

if ( $oldPath -match $lnkRegex ) {
$newPath = $oldPath -replace $lnkRegex, $newPrefix

write-host "Found: " + $_.fullname -foregroundcolor yellow -backgroundcolor black
write-host " Replace: " + $oldPath
write-host " With: " + $newPath
$lnk.targetPath = $newPath
  1. Copy the above code to Notepad, and save the file as lnk_change.ps1
  2. Make sure you input the old and new paths in lines 1 & 2 above.
  3. In line #3, specify the folder which stores the shortcuts for which you want to update the path.
  4. From the Run dialog, execute the following command:
    powershell -noexit -ExecutionPolicy ByPass -File D:\Scripts\lnk_change.ps1

    change shortcut .lnk target in bulk

That’s it. The shortcut targets are now updated from \\MEDIA to \\MEDIA-PC.

  • You can also use the full path to the resource, such as \\MEDIA\Shared and \\MEDIA-PC\SharedFolder as the “old” and “new” paths respectively.
  • In case the server name is the same but the folder path has changed, you must input the full paths in line numbers 1 & 2 respectively — e.g., \\MEDIA\Shared to \\MEDIA\SharedFolder

Hope that helps!

One small request: If you liked this post, please share this?

One "tiny" share from you would seriously help a lot with the growth of this blog. Some great suggestions:
  • Pin it!
  • Share it to your favorite blog + Facebook, Reddit
  • Tweet it!
So thank you so much for your support. It won't take more than 10 seconds of your time. The share buttons are right below. :)

Ramesh Srinivasan is passionate about Microsoft technologies and he has been a consecutive ten-time recipient of the Microsoft Most Valuable Professional award in the Windows Shell/Desktop Experience category, from 2003 to 2012. He loves to troubleshoot and write about Windows. Ramesh founded in 2005.

11 thoughts on “How to Change Shortcut (.lnk) Target in Bulk Using Script”

  1. Thanks, i was looking for something like this after merging two folders into one and all my shortcuts pointed to the separate folders but now they’re all correct thanks to your script, you saved me loads of time by not having to go through each shortcuts properties and changing them by hand.

  2. Thanks, this works for the exe. But it doesn’t change the parameters following the exe in the target field of the shortcut which also need the same text replacement made to them. Is there a way to modify the script to fix those too? (I don’t know how to program regex or powershell.)

    • @Dave: For now, please use the VBScript method (added in the article), which updates the target path, arguments, and the Start in directory automatically.

  3. I have discovered just now that the way to do this is by adding into the script the field:


    which contains any arguments that come at the end of the Target. 🙂

    • Could you help me about this issue Mark. Where should add “$lnk.Arguments” . Could you give me the exact example for this. Thanks.

  4. I have a bunch of shortcut .lnk files that have a target like \\unc1 and they also have a Start In of \\unc1. When I run the script to update the target to \\unc2, the Start In still remains \\unc1.

    Any way to fix that?

    • @Josh: For now, please use the VBScript method (added in the article), which updates the target path, arguments, and the Start in directory automatically.

  5. Hello. I have created a link to thw vbs script in my Send To folder.
    But when running the script by selecting a link file and choosing sendTo it does not work.
    VBScript gives an error when running
    Script: C:\tmp\script.vbs
    Line: 20
    Error: file not found
    Code: 800A0035


  6. Exactly what I needed after moving docs from from my old workstation. There is mention of a “preview” when hovering over the ‘Search and Replace’ toolbar icon but I don’t see the functionality in the app. Donating now!


Leave a Reply to Catcher40 Cancel reply