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.

About these ads

  1. #1 by sales propsecting on January 16, 2013 - 5:51 am

    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!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: