For most users: works 80% of the time. For the rest, locate the .exe target manually and pin that.
$shortcut = (Get-ChildItem "$env:USERPROFILE\Desktop\*.lnk" | Where-Object $_.Name -like "*MyApp*").FullName $shell = New-Object -ComObject Shell.Application $target = (New-Object -ComObject WScript.Shell).CreateShortcut($shortcut).TargetPath $shell.Namespace(0x0a).ParseName($target).InvokeVerb("taskbarpin") Problem: "Pin to taskbar" option missing. Cause: Desktop icon points to a non-executable, or the shortcut is broken. Fix: Use Method 3 (Pin the actual .exe ). add desktop icon to taskbar
Pinned icon opens wrong program or does nothing. Cause: The original desktop shortcut had command-line arguments or a specific working directory that you lost. Fix: Create a new shortcut to the .exe including arguments, then pin that new shortcut’s target. For most users: works 80% of the time