Calling exe’s with parameters from powershell

I have just spent quite a bit of time trying to get a powershell script to be able to call an external program, I knew about the & operator and I could get it to work by calling the exe with no parameters:

& "c:\foo\MyProgram.exe"

But once I tried to add any I kept getting errors, I tried various different quotes around the strings in different permutations however I finally got it working by specifying no quotes at all:

& "c:\foo\MyProgram.exe" -firstParameter $firstParam, -secondParam $secondParam

Just thought I would share this so that someone else doesn’t spend their time trying various different quotes.


One thought on “Calling exe’s with parameters from powershell

  1. Wow that was unusual. I just wrote an really long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over
    again. Anyways, just wanted to say great blog!

Comments are closed.