Thousands of broken shortcuts after move of company shared files

Cerulean

[H]F Junkie
Joined
Jul 27, 2006
Messages
9,476
Greetings,

In our migration to cloud-based computer systems, we have moved the contents of a network drive to a different location. Within this shared resource, in a particular folder that users scan PDFs to, there are a few thousand [now] broken shortcuts. Fix is easy, problem is this: is there any way to update *.lnk in batch? They do not all exist in the same folder, so a scan/search would be necessary.

Would be awesome to know if a program out there exists for this. :)
 
The fileserver is running Windows Server 2012 Enterprise I believe.
 
If the previous location doesn't exist anymore you could create a DNS alias to redirect any connection from the old location to the new location. I've done that at my work when I needed to get rid of an old file server but it has hundreds of shortcuts created to it on people desktops, in documents, in programs, etc.
 
If the previous location doesn't exist anymore you could create a DNS alias to redirect any connection from the old location to the new location. I've done that at my work when I needed to get rid of an old file server but it has hundreds of shortcuts created to it on people desktops, in documents, in programs, etc.
Directory structure outside of the folder that contains hundreds of thousands to millions of folders (yes, you read correctly ... millions) is different.

For example, it used to be Z:\Scans, but is now Y:\CompanyDivision\Shared\Scans.

A DNS entry would work only if it were Z:\Scans --> Y:\Scans
 
You could always try, PowerGrep or something similar.
That tool with the right knowledge would be incredible power in batch processing and automation. :eek: Too advanced for me, though would be awesome if I learned how to use it.

EDIT: It is advanced, no kidding, but maybe if I give it a chance, play, and experiment it might just become my best friend for life. :D
 
Directory structure outside of the folder that contains hundreds of thousands to millions of folders (yes, you read correctly ... millions) is different.

For example, it used to be Z:\Scans, but is now Y:\CompanyDivision\Shared\Scans.

A DNS entry would work only if it were Z:\Scans --> Y:\Scans

You might be able to solve this with Junction points.
 
Directory structure outside of the folder that contains hundreds of thousands to millions of folders (yes, you read correctly ... millions) is different.

For example, it used to be Z:\Scans, but is now Y:\CompanyDivision\Shared\Scans.

A DNS entry would work only if it were Z:\Scans --> Y:\Scans
This is a network file server - are Z:\ and Y:\ the local paths on the server? Or the drive letters used by clients when mapping to these shares? If the former, I don't understand why they're relevant - just recreate the share Scans in the shared folder and you'll have the same relative structure (\\servername\scans). If the latter, you'll may still need to create that same top level scans share, and if the underlying hostname has changed, you'll need to set up a CNAME and disable strictnamechecking on the new server.
 
This is easy to do with a powershell logon script. You just have to decide how far you want to go with it. Do you want it to update folders on the user's desktop only, go one level deep, two levels deep, include documents folder....folders inside of the documents folder...

The more and more you add the longer and longer it takes to process (and in a logon script that's not a good thing).

Are all of the users roaming/virtual/vdi/cloud (pick your buzzword) or are they all local profiles?
 
All users are roaming profiles.

Z:\ and Y:\ are mapped network drives, not the actual paths. The actual paths are not the same, and neither is the root of the mapped network drive letter; different folder structure down to a couple levels, and then everything deeper than that is identical to the old.

On the old system, we literally had like 8 - 12 network drives. On the new system, we're only going to use one, and do not want to unnecessarily create additional shares.
 
If they are on roaming profiles and I am assuming folder redirection, you can run the powershell script on the server to go through and find every shortcut file and update the shortcuts to point to the new location.

This will take a while.....

Here is an example-

Code:
$desktop = $null
$oldPaths = '\\\\server1\\storage\\folder1','\\\\server1\\storage\\folder2','\\\\server1\\storage\\folder3'
$newPaths = '\\\\server2\\storage2\\folder1','\\\\server2\\storage2\\folder2','\\\\server2\\storage2\\folder3'
#path variables have to have double backslashes, i.e. \\\\server\\share instead of \\server\share



$shell = New-Object -ComObject WScript.Shell

$userfolders = get-childitem "\\server\users"

foreach ($user in $userfolders){
    $desktop = $user.fullname + "\Desktop"
    
    $Dir = get-childitem $desktop *.lnk
    
    foreach($file in $Dir) {
    $extension = $file.extension
    if ($extension -eq ".lnk"){
        $fname = $file.Name
        #write-host $fname
        $lnk = $shell.CreateShortcut($desktop+"\"+$fname)
        $target = $lnk.TargetPath
        $count = 0
        foreach ($oldpath in $oldpaths){
            $newpath = $newpaths[$count]
            if ($target -match $oldPath) {
                write-host "Updating shortcut target..."
                $newshortcut = $target -replace $oldpath , $newpath
                $newshortcut = $newshortcut -replace "\\\\" , "\"
                $lnk.TargetPath = $newshortcut
                $lnk.Save()
            }#end if
            $count++
        }#end foreach
    }#end foreach
}

That example only goes through the desktop folder itself, it doesn't go any deeper. I've found most people keep shortcuts on their desktop or documents folder so no real need to search for the rest of them.

In the code above, the old paths and new paths are arrays, so make the first new path value the one to replace the first value in the old path variable, and so on. It will run through all of them.

*Edit just fyi, you aren't limited to three values in the old/new paths arrays. You can do as many as you want. If you want to do the documents folder instead of the desktop just change the $desktop variable.
 
Last edited:
I'm probably glazing over something, but can't you do a search in Explorer, highlight them all, right-click-drag to where you want the shortcuts and click "Create Shortcuts Here"?
 
Back
Top