# find shortcut targets

**URL:** <https://forums.powershell.org/t/find-shortcut-targets/602>\
**Category:** PowerShell Help\
**Created:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/find-shortcut-targets/602 "2011-12-31T18:30:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![archives](https://avatars.discourse-cdn.com/v4/letter/a/bb73d2/32.png) [@archives](https://forums.powershell.org/u/archives)\
**Post date:** [December 31, 2011, 6:30pm UTC](https://forums.powershell.org/t/find-shortcut-targets/602/1 "2011-12-31T18:30:00Z")

</div>

by rob.irvin at 2013-02-13 16:44:22

> Hi.  
>   
> I’m trying to find the target of all the shortcuts that show up on the start menu. So far I have this:  
>   
> $sc = Get-ChildItem -recurse "C:\ProgramData\Microsoft\Windows\Start Menu\Programs" -include \*.lnk  
> $sh = New-Object -COM WScript.Shell  
>   
> foreach ($\_ in $sc)  
> {$sh.CreateShortcut($\_).targetpath}  
>   
> This will list all the targets but what I’m wanting is to have it also list the name of the shortcut along with the target and write it to a text file.  
>   
> Something like:  
> "my shortcut.lnk"   
> "c:\program files\my\_application\my\_application.exe"  
>   
> "myshortcut2.lnk"  
> "c:\program files\my\_application2\my\_application2.exe"  
>   
>   
> I don’t really care what format the file is in, I just want to know which target goes with each shortcut file. Any help is appreciated.  
>   
> Thanks,  
> Rob

by MattG at 2013-02-13 18:38:52

> Hi Rob,  
>   
> Personally, I would craft a custom object consisting of the shortcut name and its target path. I would then write the output to a CSV file using the following code:  
> `function Get-StartMenuShortcuts{ $Shortcuts = Get-ChildItem -Recurse "$Env:ProgramData\Microsoft\Windows\Start Menu\Programs" -Include *.lnk $Shell = New-Object -ComObject WScript.Shell foreach ($Shortcut in $Shortcuts) { $Properties = @{ ShortcutName = $Shortcut.Name Target = $Shell.CreateShortcut($Shortcut).targetpath } New-Object PSObject -Property $Properties } [Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null}$Output = Get-StartMenuShortcuts$Output$Output | Export-Csv -LiteralPath .\shortcuts_targets.csv`

by rob.irvin at 2013-02-14 08:39:18

> Thanks! That is exactly what I need. The only thing, when I ran it in Powershell plus IDE, it complained about the last line "-literalPath"  
> Anyway I slightly changed the last line and it works perfectly. Thank you so much.  
>   
> $Output | Export-Csv -path C:\temp\shortcuts.csv -NoTypeInformation  
>   
> -Rob

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 9:04pm UTC](https://forums.powershell.org/t/find-shortcut-targets/602/2 "2024-05-16T21:04:32Z")

</div>


