Find Shortcuts and change for all users

I have just been notified that my company is changing Citrix Farms this weekend. I need to change the target path or any shortcut on any desktop to another. Sometimes the shortcut is called Cerner, sometimes BAP, sometimes NetScaler.

Would anyone be able to provide me guidance on how to lookup the target path for every shortcut in every desktop and change the target path?



I normally use c# to iterate through all the user profiles on the machine and delete the file whenever found

Alternatively email me directly, I’ll share the c# code with you. My email is

Poor English alert!

Good afternoon!

We went through a similar situation here where I work. A client\server software was replaced by a web system and we needed to replace the application shortcut target on all machines before actually removing the application.

To solve the problem we created a compliance rule through SCCM that ran a Powershell script on the machines doing the target substitution of the shortcuts, pointing the target to the web application link. Here is an adapted script that may help you. You can adapt it within the PSADT Toolkit.

I tested it a few times on my workstation and it worked the way I wanted it to.

I hope it helps.

# "BAP.lnk","Cerner.lnk","NetScaler.lnk"
$ShortCuts = Get-ChildItem -Path "C:\Users" -Recurse -Force -File -Filter "*.lnk" -Include "CLICK.lnk","CLACK.lnk","BOOM.lnk" -ErrorAction SilentlyContinue | select FullName -ErrorAction SilentlyContinue
if ($ShortCuts) {
    foreach ($ShortCut in $ShortCuts) {
        Remove-Variable -Name SC_ToChange,SC_ToWrite,WshShell -ErrorAction SilentlyContinue
        $SC_ToChange = $ShortCut.FullName
        if (Test-path -Path "$SC_ToChange" -PathType Leaf -ErrorAction SilentlyContinue) {
            if (Select-String -Path "$SC_ToChange" -Pattern "notepad.exe" -SimpleMatch -Quiet -ErrorAction SilentlyContinue) {
                $WshShell = New-Object -ComObject WScript.Shell
                $SC_ToWrite = $WshShell.CreateShortcut("$SC_ToChange")
                $SC_ToWrite.TargetPath = "c:\Windows\CCM\CMTrace.exe"
                # $SC_ToWrite.IconLocation = "C:\ICON_PATH\APP.exe,0"
                # $SC_ToWrite.Arguments = "TARGET_ARGUMENTS"
1 Like

Thank you so much! This is exactly what I was looking for!



1 Like

Thank you so much! I don’t know c# at all though. Am still trying to learn powershell.

TargetPath = "K:\APPL\Intelec\nen\Wnet32.exe"
$WorkingDirectory = $TargetPath.Substring(0, (($TargetPath.Length) - 11))
$GetFolderPathDesktop = ($GetFolderPathDesktop).replace(“OneDrive - ENGIE_Roaming”, “”)
New-Shortcut -Path “$GetFolderPathDesktop$Description.lnk” -TargetPath $TargetPath -IconLocation $TargetPath -Description $Description -WorkingDirectory $WorkingDirectory

Thank you so much! This works perfectly!!!



1 Like

That’s good, I’m glad it worked!