I have been referring to answer number three of this post to write my PowerShell script, but it doesn't appear to be working.


$linkPath        = Join-Path ([Environment]::GetFolderPath("Desktop")) "My shortcut.lnk"
$targetPath      = Join-Path ([Environment]::GetFolderPath("MyDocuments")) "...\run.exe"
$link            = (New-Object -ComObject WScript.Shell).CreateShortcut($linkPath)
$link.TargetPath = $targetPath

## Added after grawity's post
$link.Save()

It only prints out the code in the output pane but never seems to fully execute; no shortcut shows up on the desktop.

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

You need to call the Save method of the shortcut object to actually store the shortcut as a file.

$link.Save()

See also:

link|improve this answer
Whoops, thank you for pointing that out! – Mike Dtrick Jan 1 at 15:39
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.