Invoking PowerShell from cmd.exe

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!


Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: