我试图将未解析的参数“通过”传递给函数调用,但是在获取Powershell解析它们的麻烦。参见下面的代码:
[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
结果:
.\argstest.ps1 -c f1 -s1
Unbound Args: -s1
s1: False