0

I have a powershell script which executes perfectly when run from a Powershell commandline. I however need to incorporate this script into an Azure Pipeline (Classic) powershell Task, but it just won't run and is persistently erroring on the CmdletBinding method.

Immediately below is a snippet of the lines of code which is failing and further down is a screenshot of the error I'm getting.

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $false, HelpMsg = "The environment short codes array. Defaults to 'dev', 'qa', 'sit', 'uat' & 'pre' ")]
    [string[]] $Environments = @('dev', 'qa', 'sit', 'uat', 'pre', 'prod')
)

enter image description here

Any idea how I can get round this issue?

hitman126
  • 699
  • 1
  • 12
  • 43

1 Answers1

0
    [Parameter(Mandatory = $false, HelpMsg = "The environment short codes array. Defaults to 'dev', 'qa', 'sit', 'uat' & 'pre' ")]
    [string[]] $Environments = @('dev', 'qa', 'sit', 'uat', 'pre', 'prod') ) ```

There is no parameter Attribute property named HelpMsg in Parameter Attribute object in ParameterAttributeClass. You can update the pipline instead HelpMsg property with HelpMessage as shown in below which worked in local environment.

[CmdletBinding()]
Param(
    [Parameter(
        Mandatory = $false,
    HelpMessage= "The environment short codes array. Defaults to 'dev', 'qa', 'sit', 'uat' & 'pre'"
)]
[string[]] $Environments = @('dev', 'qa', 'sit', 'uat', 'pre', 'prod')
)

You can set the following properties with the ParameterAttribute object:

HelpMessage                     Property   string HelpMessage {get;set;}
HelpMessageBaseName             Property   string HelpMessageBaseName {get;set;}
HelpMessageResourceId           Property   string HelpMessageResourceId {get;set;}
Mandatory                       Property   bool Mandatory {get;set;}
ParameterSetName                Property   string ParameterSetName {get;set;}
Position                        Property   int Position {get;set;}
ValueFromPipeline               Property   bool ValueFromPipeline {get;set;}
ValueFromPipelineByPropertyName Property   bool ValueFromPipelineByPropertyName {get;set;}
ValueFromRemainingArguments     Property   bool ValueFromRemainingArguments {get;set;}

Here is the reference Azure documentation , discussing about each property of ParameterAttribute with Sample example.

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12