Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

PowerSQL By Prashanth Jayaram

Technology enthusiast with 7+ years of experience in Database Technology. I am Microsoft Certified Professional with certificates of OCA, MCP, MCTS, MCITP developer, MCITP administration and backed with a degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication, PowerShell and Performance Tuning. Hobbies are Drawing, playing soccer and listening to Melodies songs.

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 [user[:perm][ /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!!!


Comments

Leave a comment on the original post [sqlpowershell.wordpress.com, opens in a new window]

Loading comments...