Skip to content

Parameters after the double dash -- are not forwarded properly to the "pwsh" shell #398

@tusharb86

Description

@tusharb86

This is a great tool and my team uses it heavily for local development. Thank you!!

We are hitting the following issue which has been very challenging to work around. We end up with many scripts to call the same PowerShell script with different parameters. Instead, we would prefer to use the -- and pass parameters to the underlying PowerShell script that way, if this was fixed. Here is the issue:

If we run .\run-script.exe get-test-account -- -Environment PROD, we the get this error:
Get-TestAccount.ps1: A positional parameter cannot be found that accepts argument '-Environment'.

We would hope to get this instead:
This is Get-TestAccount.ps1: AnotherParam = , Environment = PROD, Alias = testuser, AsPlainText = True, args =

Example PowerShell script:

#Requires -Version 7.0

[CmdletBinding(DefaultParameterSetName = 'Alias')]
param (
    [string] $AnotherParam,

    [ValidateSet("PPE", "PROD")]
    [string] $Environment = "PPE",

    [ValidateNotNullOrEmpty()]
    [Parameter(Position = 0)]
    [string] $Alias,

    [switch] $AsPlainText
)

Write-Host "This is Get-TestAccount.ps1: AnotherParam = $AnotherParam, Environment = $Environment, Alias = $Alias, AsPlainText = $AsPlainText, args = $args"

Example global.json to invoke the script:

{
  "scriptShell": "pwsh",
  "scripts": {
    "get-test-account": "./Get-TestAccount.ps1 -AsPlainText -Alias testuser"
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions