We help IT Professionals succeed at work.

USing loop in powershell to run different .exe files at different locations.

Aakash Aggarwal
on
Please check the below screenshot.

The first command in powershell is running fine, however I need to run the same command for 8 different .exe files. I have mentioned the paths where I need to run the command.

Assist if any idea how I can put those in a loop and run the script for all simultaneously.
myscript.PNG
Comment
Watch Question

@aakash It would be more helpful if you could paste your script content in code blocks rather than in a PNG format. This would make it faster to answer your question and not have to rewrite all the code.
You could try this :

 I am presenting the code untested.

$myscript =  "D:\script_run\mysql.xml"
$xml = [xml](get-content $myscript)
$EnvironmentCode = $xml.Synergetic.Parameters.EnvironmentCode
$SERVERNAME = $xml.$Envi.Synergetic.Parameters.SQLServerName
$LOGINUSERNAME = $xml.$Envi.Synergic.Parameters.LOGINUSERNAME
$LOGINPASSWORD = $xml.$Envi.Syergetic.Parameters.LOGINPASSWORD
$DBNAME = $xml.$Envi.Synergetic.Parameters.DBNAME

Function  invoke-script($Path){
        set-location $path
        & Synergetic.Application.CreateConfigCommandLine.exe /SERVERNAME = "$SERVERNAME" /LOGINUSERNAME = "$LOGINUSERNAME" /DBNAME = "$DBNAME" /CONSOLELOG=1

}

#invoke-script -Path "D:\InetPub\wwwroot\" 
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\OnlineApplication\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCommunityPortal\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\CoreAPI\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\EventBooking\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\OnlineApplication\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\OnlineEnquiry\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\SunAPI\BinConfig"
invoke-script -Path "D:\InetPub\wwwroot\SynergeticCore\WebService\BinConfig"

Open in new window

Changed the Code a little bit. I wasn't sure if you had an executable in "
invoke-script -Path "D:\InetPub\wwwroot\" 

Open in new window


If you don't just remove the line or comment it out.

Please note: I typed all that freehand so there are probably some typo's

Author

Commented:
Thanks