Bishal Thingom
Bishal Thingom

Reputation: 131

How to pass selected arguments to Powershell script which accepts multiple argumnets in Microsoft TFS?

I have a script which takes arguments as

.\script1.ps1 -Arg1 "Argument 1" -Arg2 "Argument 2"

I have set the format for arguments in TFS as:

.\script.ps1 -Arg1 $($arg1) -Arg2 $($Arg2)

I get the following error when I try to pass just Arg2:

Missing an argument for parameter 'Arg1'. Specify a parameter of type 'System.String[]' and try again.

Upvotes: 0

Views: 1192

Answers (1)

Eddie Chen - MSFT
Eddie Chen - MSFT

Reputation: 29976

According to your question, you are placing the arguments in variables. And I suspect that you just enter the value for $Arg2 variable when you try to pass just Arg2. In this scenario, the powershell script is run in the following format will the cause the error message you got since the Arg1 argument is empty:

.\script.ps1 -Arg1 -Arg2 Arg2Value

A workaround for this would be using variable to control the arguments directly. For example, add two variable in the build definition: Arg1 and Arg2 enter image description here

And in the PowerShell script task arguments, just enter: $(Arg1) $(Arg2) enter image description here

With this, you can simply set the Arg1 variable to empty when queue the build if you only want to pass Arg2.

Upvotes: 1

Related Questions