dotnet-run-script icon indicating copy to clipboard operation
dotnet-run-script copied to clipboard

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

Open tusharb86 opened this issue 3 months ago • 1 comments

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"
  }
}

tusharb86 avatar Sep 17 '25 21:09 tusharb86

@xt0rted - I have a proposed fix for this issue and have opened the following PR to resolve it: #399 . Please let me know if you have feedback or questions! I may have misunderstood how this was supposed to work for pwsh, so please let me know if that's the case.

If the change looks good and it can be merged, do you happen to have an idea of when you plan to make a new release? My team would love to benefit from this fix ASAP. Thanks again for making a great tool!

tusharb86 avatar Sep 17 '25 22:09 tusharb86