Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a .Bat with mutliple Parameters from Powershell scripts

how do I execue a .bat from a powershell script.

I want to do something like:

foreach($item in $list){

  param1= $item.Name
  param2= $item.path

  C:\Filesystem_Batches\test.bat param1 param2

}

Thank you

like image 660
PointerNullException Avatar asked Dec 19 '12 10:12

PointerNullException


Video Answer


2 Answers

You can call

cmd.exe /C "test.bat param1 param2"

In powershell V3 there is a new espace string --% which allow to send "weird" parameters to your exes. exemple :

PS> echoargs.exe --% %USERNAME%,this=$something{weird} 

Arg 0 is <jason,this=$something{weird}>
like image 105
Loïc MICHEL Avatar answered Nov 15 '22 09:11

Loïc MICHEL


I am new to Powershell but the following works for me. I am able to run the *.bat from my *.ps1 file. And I am using Powershell 5.1.17134.590.

& .\myFile.bat parm1
like image 29
J Z Avatar answered Nov 15 '22 07:11

J Z