Posts Tagged ‘cmd’

Invoking PowerShell from cmd.exe

November 22, 2008

Microsoft PowerShell is a marvelous technology, and according to some linux developers the only reason they are jealous of not working  on Windows 🙂

Being so powerfull, I wanted to use it in our build script, but unfortunately it was hard to invoke a powershell script from the command line – cmd.exe.
Surprisingly there is no command line option for executing scripts, which is obvious to me and probably  one of the most important use cases.
After struggling for a while I finally found a blog post about it and want to spread the word and maybe help someone with the same problem
So here it is:

powershell " & 'C:\path\to\script.ps1' "

Invoked with one argument in quotes, powershell executes the string as script. So the trick here is to invoke it, and use the & ‘script_file.ps1’ command to make it execute your script.

Good luck everyone and happy programming!