Share via


Execute .ps1 script silently

Question

Sunday, August 21, 2016 3:01 PM

Hi, 

I'm new to Powershell so please bear with me.  My .ps1 files are associated with Powershell.exe so when I run them from the command line they open up "Powershell ISE" and wait for me to press play. Is there a way of just having them execute without this popping up? 

I had a look at the Powershell editor and it looked fine for testing out single line commands, however I did not seem to be able to comment/uncomment lines easily so I decided to use Visual Studio 2015 Enterprise as I'm familiar with the IDE, am I likely to run into any issues/limitations further down the road using this?

Thanks

  

All replies (2)

Sunday, August 21, 2016 10:46 PM ✅Answered

Hi,

If you run them from the command line, then yes, they will open using the program you see in your screenshot under "opens with". This is because they are PowerShell commands, not native command prompt commands.

From the command line, you need to run the "powershell" command first. I mean that literally - just type "powershell" to open the PowerShell environment.

Once you have done that, then you can run your .ps1 file and it will run as it was intended, not open in the ISE.

I'm not sure what your issue is with managing comments, however, it doesn't matter what choice of editor you use. I often use Notepad but I've never had an issue with the ISE and while I personally don't have a need, using Visual Studio is fine.

Cheers,
Lain


Monday, August 22, 2016 6:14 AM ✅Answered | 1 vote

Hi there,

A little more visualize supplement:

For example, I have a .ps1 file and it was associated with some 3rd applications, when I need to open it to execute, I just need to open cmd prompt then type powershell.exe and input .\test.ps1 then this file will runs as expected.

See figure below:

>>am I likely to run into any issues/limitations further down the road using this?

You really don't need to worry too much, if you have any issues during using powershell, welcome to post here.

You could also use some intelligent tools to make your .ps1 file as a .exe file for windows.

Best regards,

Andy_Pan

Please remember to mark the replies as an answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected].