Site icon Winhelponline

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.

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

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:

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

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

Hope that helps!

Exit mobile version