Run a PowerShell script from desktop


I am experimenting with PowerShell. I want to run a PowerShell script from my desktop. I noticed that if I double-click on the script then it opens with Notepad or the PowerShell editor. What do I need to do so that if I double-click on TEST.PS1 that it runs in PowerShell rather than open up in the editor or Notepad?

I am looking for other uses for running PowerShell, and want to start creating more scripts. So, if you have any additional advice and hyperlink examples on how to start and run PowerShell scripts from the desktop and the Windows Command prompt I would appreciate it.

I am testing under Windows 7 and 8.1

Who is Participating?
Thomas GrassiConnect With a Mentor Systems AdministratorCommented:
try this

start run type
powershell.exe -noexit c:\scripts\test.ps1

you may need to place the path to powershell.exe too.

Run this first to make sure you can execute powershell scripts on your computer


Set-executionpolicy unrestricted
footechConnect With a Mentor Commented:
I don't think that I would recommend changing the default action.  Too easy for someone to accidentally run a script.  You always have the option to right-click and choose "Run with PowerShell".  But changing the default action would be same as any other file association - if you change it to PowerShell instead of Notepad it will work.
If you want to run a PS script from a command prompt, or as a scheduled task, you call powershell.exe and pass the script as an argument.  Run powershell /? to see the available switches.
QlemoConnect With a Mentor DeveloperCommented:
Instead of changing the default action I recommend to put a shortcut onto the desktop with powershell -noexit -file, and then drag your PS1 file onto that shortcut to execute.
You might have to change the "Start in" folder to the desktop or something more useful than the PS folder.
jhiebAuthor Commented:
Thanks everyone for your help and suggestions. I appreciate it.
All Courses

From novice to tech pro — start learning today.