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

3)

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

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

http://social.technet.microsoft.com/Forums/windowsserver/en-US/b9e0f4f3-ae5d-4c8f-8f80-1600e8b63446/run-executable-from-powershell-passing-parameters-and-return-result?forum=winserverpowershell

 

 

 

 

 

 

Advertisement

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 )

Facebook photo

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

Connecting to %s