Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 3 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:

share|improve this answer
    
Whoops, thank you for pointing that out! –  mdeitrick Jan 1 '12 at 15:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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