Question about desktop shortcuts

Is it possible to have an application desktop shortcut, upon double-clicking to launch, run a ps1 script BEFORE opening the application?
All resources I find online are for creating shortcuts TO the Powershell script. I need the trigger to be the app desktop shortcut/icon, and run the script completely prior to opening the app. Possible? If so, can someone please describe what to use.

Thank you.

Hello Bryan,

Why doesn’t launching the application from within the Powershell script solve your problem? That way the script runs before launching the application doesn’t it?

Kris.

Hi Kris,

That’s what I was originally hoping to do along with simply adding the necessary extracted icon, but come to find out it wasn’t going to work anyway due to script running restrictions in my organization.

We are able to handle this through Group Policy, so this is no longer an issue. (whew)

Thanks for your response.

you can have the shortcut run powershell.exe and add the script you need to run as an argument

 

powershell.exe -file "pathtoyourscript.ps1"

Here is a link to the powershell.exe command line help

 

You could also use a helper script that will run your script and then run the application

 

 

https://gist.github.com/kpatnayakuni/395dda9fabcdd5170a1a01aedce5e5b4

Hey guys, along the same lines. How would I launch an application on my laptop within Powershell just as Kris alluded to above. For instance I have an RPA tool, Automation Anywhere and I would like to launch it. How can I accomplish this?

Thanks in advance!

 

Thank you for the additional options here, Kiran and Conor.
I’ll look into testing these as well.

Greatly appreciate it!

If it’s just an application that you need to start from within PS, then Start-Process should be the cmdlet you need for that.

Take a look at Get-Help Start-Process to start.

[quote quote=136196]If it’s just an application that you need to start from within PS, then Start-Process should be the cmdlet you need for that.

Take a look at Get-Help Start-Process to start.

[/quote]
Thank you KLaage, will give it a shot!