views:

2195

answers:

2

I've found a nasty VBS way to do this, but I'm looking for a native PoSh procedure to edit the properties of a .LNK file. The goal is to reach out to remote machines, duplicate an existing shortcut with most of the correct properties, and edit a couple of them.

If it would just be easier to write a new shortcut file, that would work too.

+1  A: 

I don't think there's a native way.

There is this DOS util: Shortcut.exe.

You still need to copy the util to the remote system, then possibly call it using WMI to make the changes you're looking for.

I'm thinking the easier way will be to overwrite and/or create a new file.

Do you have access to these systems via a remote share?

Marco Shaw
Hi Marco. Sure, I can access them via a remote share.
Doug Chase
Well, I don't do enough regular admin stuff like this, but I'm thinking you can simply use the share to update the lnk file remotely.
Marco Shaw
+3  A: 
Copy-Item $sourcepath $destination  ## Get the lnk we want to use as a template
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($destination)  ## Open the lnk
$shortcut.TargetPath = "C:\path\to\new\exe.exe"  ## Make changes
$shortcut.Description = "Our new link"  ## This is the "Comment" field
$shortcut.Save()  ## Save

Found the VB version of the code here: http://www.tutorialized.com/view/tutorial/Extract-the-target-file-from-a-shortcut-file-.lnk/18349

JasonMArcher