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"

0

1 Answer 1

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"
Sign up to request clarification or add additional context in comments.

1 Comment

That's it. After your answer, I still had this problem 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 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.