New
#1
PowerShell - Get FULL TargetPath of Shortcut
Good evening,
As I have setup a LOT ofShortcuts
in a specific folder, I wanted to find a way of extracting specific data from EACH of them, which I have managed to 90% achieve.
The only part that I am having difficulty with is the data that is in theTargetPath
field, because it excludes ANY data [ commands ] after a specific point.
I have setup a.BAT
file and a.PS1
file for this which obviously works from having the SAME Filename.
BAT
Code:@echo off & mode con: cols=30 lines=1 & color A & C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -ExecutionPolicy Bypass %~dp0%~n0.ps1
PS1
Code:Function Get-DesktopShortcuts{ $Shortcuts = Get-ChildItem -Recurse "C:\System-Admin_ToolBar" -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-DesktopShortcuts $Output | Out-GridView ;Pause
ItOutputs
the data inGridView
.
As an EXAMPLE of my problem, if I was to use myShortcut
forDisk Cleanup - Advanced Mode
, theGridView
forTarget
shows . . .
But, in theProperties
of theShortcut
, there is extra data AFTER the\cleanmgr.exe
. . .
So my question is, how do I get it to show the FULL data in theTargetPath
field [ the/sagerun:65535
] please.
EVERYTHING works except that particular bit.
Thanks.