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.
- You can use Invoke-Expression
- 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!!!