PMP Style .global

PMP Style .global

Software engineer page

MENU

Run the shortcut file from PowerShell

Explains how to execute the link destination of the shortcut file from PowerShell.
First, the shortcut creates a filter function with the help of Wsh (Windows Script Host). If you make a filter, it can also be used as a pipe, so it is convenient because it has a high affinity with PowerShell.

filter Get-Shortcut()
{
    $shl  = new-object -comobject WScript.Shell
    return $shl.CreateShortcut($_)
}

Preparation is now complete

All you have to do is call it in conjunction with Start-Process.
You can see that Get-Shortcut blends in like a standard command.

# This is fine for one process
Start-Process ('c:\temp\test.lnk' | Get-Shortcut).TargetPath

# If you want to start multiple processes, use the list. This one seems to be PowerShell. 
$list = @('a.lnk', 'b.lnk', 'c.lnk')
$list | Get-Shortcut | % { Start-Process $_.TargetPath }

You can see what kind of members there are by displaying the output of Get-Shortcut.
Try it with the link to notepad (a.lnk) ...

PS C:\temp> 'c:\temp\a.lnk' | Get-Shortcut
FullName         : c:\temp\a.lnk
Arguments        : 
Description      : 
Hotkey           : 
IconLocation     : ,0
RelativePath     : 
TargetPath       : C:\Windows\System32\notepad.exe
WindowStyle      : 1
WorkingDirectory : C:\Windows\System32

The nice thing about PowerShell is that you can easily see the list of members and their values.
If you don't understand something, you can display it and check it.