PowerShell – Execute Batch files & Executable file, Exes – Dynamically passing Parameters

In PowerShell you can execute a executable in 3 ways

  1. Using Invoke-Expression
  2. Call operator ‘&’  “invocation operator”
  3. System.Diagnostics.ProcessStartInfo


Original command c:\Progra~1\NetApp\snapdrive\sdcli.exe snap mount -r  -k -d X -s sqlsnap__sql_08-14-2014_10.15.41

1) Invoke-Expression

$snap= “snap mount -r  -k -d X -s sqlsnap__sql_08-14-2014_10.15.41”

Invoke-Expression -Command “c:\Progra~1\NetApp\snapdrive\sdcli.exe $snap”

2)Call operator

& “c:\Progra~1\NetApp\snapdrive\sdcli.exe ” $snap


$psi = New-Object System.Diagnostics.ProcessStartInfo “c:\Progra~1\NetApp\snapdrive\sdcli.exe”
$psi.Arguments = $snap

please refer to this documentation on http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx to customize









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 )

Google+ photo

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

Connecting to %s