I am NOT
really up with PowerShell
, but I would find this useful because I have a Toolbar
with MANY Shortcuts
, and it would be very useful to have the Target:
and Start in:
entries. Even the Icon Name
and Icon Path
for Custom Icons
that are used.
I will have a look into this tomorrow for either a Batch Script
or PowerShell Script
solution.
The target of a .lnk file is available as a column in Explorer:
So a Filter can be created to invoke Add-Member add the target as a propetrty of the FileInfo object retruned by Get-ChildItem
:
Code:
Filter Add-LnkTarget
{
If ( $_.Extension -notLike '.lnk' )
{
$_ | Add-Member -NotePropertyName LnkTarget -NotePropertyValue $Null
}
Else
{
$S = { (New-Object -Com shell.application).NameSpace($this.DirectoryName).ParseName($this.Name).ExtendedProperty('LinkTarget') }
$_ | Add-Member -MemberType ScriptProperty -Name LnkTarget -Value $s -PassThru
}
}
And can then be used in the pipeline:
Code:
gci | Add-LnkFileTarget | select name , LnkFileTarget | ft -AutoSize -Wrap
If you want all the properties of a .lnk file, make the property a custom object:
Code:
Filter Add-LnkInfo
{
If ( $_.Extension -notLike '.lnk' )
{
$_ | Add-Member -NotePropertyName LnkInfo -NotePropertyValue $Null
}
Else
{
$wsh = New-Object -Com wscript.shell
$s2 = { [PSCustomObject](($wsh.CreateShortcut($This.FullName)).PSObject.Properties | % -Begin {$hash=@{}} -Process {$hash.Add($_.Name,$_.Value)} -End {$hash}) }
$_ | Add-Member -MemberType ScriptProperty -Name LnkInfo -Value $s2 -PassThru
}
}
and could be used like this:
Code:
gci *.lnk | Add-lnkInfo | select name , {$_.LnkInfo.TargetPath} , {$_.LnkInfo.WorkingDirectory} | Format-List
--- or ---
Code:
gci *.lnk | Add-lnkInfo | select name -ExpandProperty LnkInfo | Out-GridView
If you add the Filter defintions to your PowerShell profile, they'll be available in every PS session.