How do I run a PowerShell script?
- I have a script named myscript.ps1
- I have all the necessary frameworks installed
- I set that [execution policy](https://stackoverflow.com/questions/10635/why-dont-my-powershell-scripts-run) thing
- I have followed the instructions on [this MSDN help page](http://technet.microsoft.com/en-us/library/ee176949.aspx)
and am trying to run it like so:
`powershell.exe 'C:\my_path\yada_yada\run_import_script.ps1'` (with or without `--noexit`)
which returns exactly nothing, except that the file name is output.
No error, no message, nothing. Oh, when I add `-noexit`, the same thing happens, but I remain within PowerShell and have to exit manually.
The .ps1 file is supposed to run a program and return the error level dependent on that program's output. But I'm quite sure I'm not even getting there yet.
What am I doing wrong?
Comment exécuter a PowerShell script
Re: Comment exécuter a PowerShell script
Prerequisites:
- You need to be able to run PowerShell as an administrator
- You need to set your PowerShell execution policy to a permissive value or be able to bypass it
Steps:
-
Launch Windows PowerShell as an Administrator, and wait for the `PS>` prompt to appear
-
Navigate within PowerShell to the directory where the script lives:
```
PS> cd C:\my_path\yada_yada\ (enter)
```
-
Execute the script:
```
PS> .\run_import_script.ps1 (enter)
```
Or: you can run the PowerShell script from the Command Prompt (`cmd.exe`) like this:
```
powershell -noexit "& ""C:\my_path\yada_yada\run_import_script.ps1""" (enter)
```
according to [*Invoking a PowerShell script from cmd.exe (or Start | Run)*](http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/) by Kirk Munro.
Or you could even [run your PowerShell script asynchronously from your C# application](http://www.codeproject.com/KB/threads/AsyncPowerShell.aspx).
- You need to be able to run PowerShell as an administrator
- You need to set your PowerShell execution policy to a permissive value or be able to bypass it
Steps:
-
Launch Windows PowerShell as an Administrator, and wait for the `PS>` prompt to appear
-
Navigate within PowerShell to the directory where the script lives:
```
PS> cd C:\my_path\yada_yada\ (enter)
```
-
Execute the script:
```
PS> .\run_import_script.ps1 (enter)
```
Or: you can run the PowerShell script from the Command Prompt (`cmd.exe`) like this:
```
powershell -noexit "& ""C:\my_path\yada_yada\run_import_script.ps1""" (enter)
```
according to [*Invoking a PowerShell script from cmd.exe (or Start | Run)*](http://poshoholic.com/2007/09/27/invoking-a-powershell-script-from-cmdexe-or-start-run/) by Kirk Munro.
Or you could even [run your PowerShell script asynchronously from your C# application](http://www.codeproject.com/KB/threads/AsyncPowerShell.aspx).