Blog Post

PowerShell – Invoke Commands,Batch files & Executable file – Dynamically passing Parameters

,

I’ve recently got a request to invoke an executable file from Powershell. Different ways of executing a executable file is given below. The advantage is that either you can pass the parameters dynamically by reading it from a text file or using variables.

  1. You can use Invoke-Expression
  2. Use of  call operator ‘&’ ["invocation operator"] –  Run a command, script, or script block.  The call operator does not parse the command, it cannot interpret command parameters.

I’m invoking RMTSHARE.EXE. The syntax is given below

RMTSHARE  \\server\sharename=drive:path  [/GRANT [ /GRANT user[:perm]]]

Eample 1:

$ser = “adbpsp18″ ; $user = “XYZ” ; $SrvPath = “F:\PowerSQL\Input”

Invoke-Expression -Command “C:\RMTSHARE.EXE \\$ser\$user$=$SrvPath /GRANT qnts\cc648:full”

Example 2:

$ser = “adbpsp18″ ; $user = “XYZ” ; $SrvPath = “F:\PowerSQL\Input”

&”C:\RMTSHARE.EXE” \\$ser\$user$=$SrvPath /GRANT qnts\cc876:full

 Thanks for reading!!!

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating