Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to launch PowerShell script from the OS command line?

Tags:

I have a PowerShell script for building my project files, and I'd like to have capability to run it from my file manager's command line (and, possibly, make a shortcut to this script so I can start build from my desktop)
Any way to do this?

like image 523
skevar7 Avatar asked Jul 24 '10 08:07

skevar7


People also ask

How do I run a PowerShell script from the command line?

Running a PowerShell script from the Command Prompt If you would like to run a PowerShell script in CMD, you'll need to execute it by calling the PowerShell process with the -File parameter, as shown below: PowerShell -File C:\TEMP\MyNotepadScript. ps1. PowerShell -File C:\TEMP\MyNotepadScript.

How do I run a PowerShell script from the command line in Linux?

To start PowerShell, simply run pwsh and you'll be dropped into the PowerShell interactive console. Being a cross-platform scripting language, PowerShell on Linux supports all of the commonly known commands from CMD and Linux's command line shell such as sudo apt update .

How do I open PowerShell from terminal?

Click Start, type PowerShell, and then click Windows PowerShell. From the Start menu, click Start, click All Programs, click Accessories, click the Windows PowerShell folder, and then click Windows PowerShell.

How do I run a PowerShell script from the command line with parameters?

You can run scripts with parameters in any context by simply specifying them while running the PowerShell executable like powershell.exe -Parameter 'Foo' -Parameter2 'Bar' . Once you open cmd.exe, you can execute a PowerShell script like below.


1 Answers

If you're on PowerShell 2.0 use:

PowerShell.exe -File c:\users\john\myscript.ps1 

If you're on 1.0 use:

PowerShell -Command "& {c:\users\john\myscript.ps1}" 

Depending on what you do/load in your profile script you may also want to specify -NoProfile. Of course, if your script requires something that is loaded in your profile then don't use this parameter. Otherwise, it can speed up execution of your script a bit.

like image 190
Keith Hill Avatar answered Sep 19 '22 17:09

Keith Hill