How to print a text file which is the target of a .lnk file to the Powershell Console

Viewed 43

How do you print the text content of a file which is being linked to by a Shortcut file?

1 Answers

I went and looked at the documentation: Creating .NET and COM Objects.

This gave me the template for the commands needed to write the target file to the console.

How it is done:

$WshShell = New-Object -ComObject WScript.Shell
$lnk = $WshShell.CreateShortcut("C:\Users\whitequill\Documents\PowerShell\Profile.ps1.lnk")
Get-Content $lnk.TargetPath

This does NOT create a shortcut. For some reason, the method is called CreateShortcut to read or write a Shortcut file. In my example, Profile.ps1.lnk is a shortcut I made previously.

Related