Dealing with multiple parameters passed to exe in powerhsell

If you have ever needed to call an exe application from PowerShell and needed to pass multiple parameters to the exe then the technique I outline here will really help you out.

Declare a variable that holds the executable name as a string and any other variables you might want to use

$pfm = “pfm”

$MountPath = “T:”

As a side note the application I am calling is Pismo File Mount which is by far the best free (even for commercial use) software I have ever used for mounting ISOs

Declare all your parameters as an object array

$Mount = “mount”,”-m”,”$MountPath”

Now in your code you can do the following

& $pfm $Mount “$MSDNIsoPath\en_visual_studio_2010_premium_rc_x86_dvd_489527.iso”

If I wanted to write out all my parameters every time I could always write in PowerShell:

Pfm mount -m “$MountPath” “$MSDNIsoPath\en_visual_studio_2010_premium_rc_x86_dvd_489527.iso”

I can’t say as I have figured out why this works this way and if anyone has an explanation I would love to hear it in the comments.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: