?
Solved

Run a PowerShell script from desktop

Posted on 2013-12-10
4
Medium Priority
?
1,240 Views
Last Modified: 2013-12-10
Hello,

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

Thanks
0
Comment
Question by:jhieb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 23

Accepted Solution

by:
Thomas Grassi earned 1200 total points
ID: 39709727
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

Get-executionpolicy

Set-executionpolicy unrestricted
0
 
LVL 40

Assisted Solution

by:footech
footech earned 400 total points
ID: 39709838
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.
0
 
LVL 70

Assisted Solution

by:Qlemo
Qlemo earned 400 total points
ID: 39710018
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.
0
 
LVL 1

Author Closing Comment

by:jhieb
ID: 39710228
Thanks everyone for your help and suggestions. I appreciate it.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question