I found a snippet on the internet that does this
function Get-DesktopShortcuts{
$Shortcuts = Get-ChildItem -Recurse "C:\users\public\Desktop" -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
}
But I am unsure how to manipulate the results.
$output = get-desktopshortcuts
stores the results, and I can output it all $output | out-gridview
but if Target had foo.exe, I want just the path, C:\Program Files\Foo Enterprises. Since there is no guaranteed way for me to know if the enduser installed it into a non-default location, and of course the shortcut isn't guaranteed, but then i will return the default for worse case scenario.
Thank you!