How to execute ps1 script from Win 11 shortcut

I want to be able to click a Win11 desktop shortcut which then sets my copy buffer to a text string then starts an application (to have that string available to paste in the application).

The script so far is (last line for debugging):

Set-Clipboard -Value 'New Clipboard Buffer Text'
Start-Process -FilePath "C:\Program Files (x86)\Man From Uncle\Bob'sUrUncle.exe"
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');

In the shortcut, I when I set the target to the .ps1 file, it just opens it in Notepad. If I set the target to

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe 'MyPSFile.ps1'

Then a Powershell window opens then immediately closes without anything being printing in it, and the application does not start.

Any idea what I should actually be doing?

Greg,
Welcome to the forum. :wave:t3:

You may first negotiate your options ā€¦ :wink: ā€¦ try running ā€¦

powershell /?

ā€¦ in a CMD or PowerShell console window to learn how to properly start the PowerShell and execute a script file from a command line.

Are you sure about that? :wink: ā€¦ you may use the command line option -NoExit.

1 Like