1

I am trying to create a Windows desktop shortcut (SymbolicLink) that runs a PowerShell script. If this were executed from the command line, it would be:

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noexit -file "C:\User\BFT\Test\HelloWorld.ps1"

And the command line does work with this.

I can also create a shortcut by right-clicking on the desktop, selecting New, selecting shortcut, and loading the above command into the dialog. This also works just fine.

When I attempt to create this shortcut in PowerShell using the command:

New-Item -ItemType SymbolicLink -Path "c:\User\BFT\Test" -Name "Test" -Target """C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -noexit -file "C:\User\BFT\Test\HelloWorld.ps1"""

I receive an error saying

New-Item : A parameter cannot be found that matches parameter name 'noexit'.

I have tried several versions involving different quoting, with and without -noexit and -file, etc. None seem to work.

It would appear PowerShell can't deal with both the exe and the file path portion, but this seems like it should be a common use and I would think there is a way. I am probably missing something.

Any help in suggesting solutions would be greatly appreciated.

0

1 Answer 1

2

Shortcut files (.lnk files) aren't the same as symbolic links - see this answer for background information.

New-Item doesn't support creating shortcut files, only symbolic links,

To create shortcut files programmatically, you must use the WScript.Shell COM component, as shown in this answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.