0

I'm trying to pass unparsed arguments "through" to a function call, but am having trouble getting powershell to parse them. See below code:

[CmdletBinding(PositionalBinding=$false)] 
param([Parameter(Mandatory=$false)] [Alias("m", "mixno", "mix")] [int]$script:mix = 2,               
      [Parameter(Mandatory=$false)] [Alias("c", "command")] [String]$script:command = "help",
      [Parameter(ValueFromRemainingArguments=$true)] [string[]]$script:otherargs)

function f1{
    param([switch]$s1)
    Write-host "Unbound Args: $($MyInvocation.UnboundArguments)"
    Write-Host "s1: $s1"
}

&"$script:command" @script:otherargs

Result:

.\argstest.ps1 -c f1 -s1

Unbound Args: -s1

s1: False
Nick
  • 1,178
  • 3
  • 24
  • 36
user2563087
  • 151
  • 1
  • 8
  • Does this answer your question? [How to pass named parameters to another script in powershell](https://stackoverflow.com/questions/58507154/how-to-pass-named-parameters-to-another-script-in-powershell) – iRon Nov 08 '19 at 18:44
  • So I have to build a hash table? Seems like there should be an easier way to do it. – user2563087 Nov 11 '19 at 15:32
  • if you want to pass **named** parameters: yes. In case you want to pass **positional** parameters (which is tricky as you might have bound parameters as well), you might simply build an array of the unbound parameters. – iRon Nov 11 '19 at 15:41

0 Answers0