PowerShell:如何将未解析的参数转发给函数?

我试图将未解析的参数“通过”传递给函数调用,但是在获取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
GY176984859 回答:PowerShell:如何将未解析的参数转发给函数?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3136002.html

大家都在问