1

My final goal is to have a .bat file that calls a powershell script.

This works OK in powershell (but can't be used in a batch file):

PS build-directory> .\ps1file.ps1 -ScriptArgs '-arg1="val1"', '-arg2="val2"'

But this one (batch file friendly) fails:

PS build-directory> powershell -File ps1file.ps1 -ScriptArgs '-arg1="val1"', '-arg2="val2"'

A parameter cannot be found that matches parameter name 'arg2=val2'.

But it works fine if there is only one param -arg1="val1"

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Xavier Peña
  • 7,399
  • 9
  • 57
  • 99

1 Answers1

4

You're having problems because ScriptArgs isn't a valid parameter for using with powershell command line (documentation link).

You just pass the arguments like this:

powershell -File ps1file.ps1 -arg1 "val1" -arg2 "val2"
henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • 1
    That's it. After your answer, I still had [this problem](https://i.imgur.com/Iu6HtgH.png) with Cake Build. Before you answer I didn't know if this error was related to the `ScriptArgs` or not. After this answer, being sure that this was the right way (regarding powershell), I made [a bit of research](https://github.com/cake-build/cake/issues/1248#issuecomment-249287930) and I found that arguments containing "." did not work with "-paramName" BUT they work with "--paramName" (two "-"). This finally solved my issue. Thanks for the answer, it helped me decouple one issue from the other. – Xavier Peña Nov 01 '17 at 12:34