How to get target full path of all desktop shortcuts in Windows

Hello Everyone

While doing a clean install and Backup of my Windows 10 machine i realized that i had a lot of shortcuts which i really need to continue working smoothly upon restoring all my data. Since there are a lot them, it would be very time consuming for me to note each and every file name and path.

A command that gets them all for me together in one place would be awesome. So I began searching and trying all the various scripts available on the internet.

Finally after a lot of R&D I got the one that did the job. Here’s the steps

Open Powershell and paste below
$folder = “C:Users%username%Desktop”
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.namespace($folder)
$objFolder.Items() |
Where-Object {$_.Type -eq “Shortcut”} |
ForEach-Object {
[pscustomobject]@{
$objFolder.getDetailsOf($folder, 203) = $objFolder.getDetailsOf($_, 203)
}

Remember to change the username to your relevant name in the 1st line

Another command below will give you the path including the file extension name, if required

function Get-StartMenuShortcuts{
$Shortcuts = Get-ChildItem -Recurse $env:USERPROFILEDesktop -Include *.lnk
$Shell = New-Object -ComObject WScript.Shell
foreach ($Shortcut in $Shortcuts)
{
$Properties = @{
ShortcutName = $Shortcut.Name;
ShortcutFull = $Shortcut.FullName;
ShortcutPath = $shortcut.DirectoryName
Target = $Shell.CreateShortcut($Shortcut).targetpath
}
New-Object PSObject -Property $Properties
}
[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null
}
$Output = Get-StartMenuShortcuts
$Output.Target
 
Hope this helps, do comment if it does !!!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.