新手问题。
如何声明 Powershell cmdlet 的嵌套参数?我想要一个看起来像这样的 cmdlet。
New-FootballTeam
[-Defenders [[-LeftBack] <string>] [[-RightBack] <string>] ]
[-Midfielders [[-LeftWing] <string>] [[-RightWing] <string>] [[-CentreMidfield] <string>] ]
我尝试使用 ParameterSetName
参数将 Defenders
和 Midfielders
下的参数组合在一起。但是,当我执行 help New-FootballTeam
时,Defenders
和 Midfielders
标签不会显示,我看到类似这样的内容。
New-FootballTeam
[[-LeftBack] <string>] [[-RightBack] <string>]
[[-LeftWing] <string>] [[-RightWing] <string>] [[-CentreMidfield] <string>]
提前谢谢。
最佳答案
PowerShell 不支持您所描述的参数嵌套。 PowerShell 支持多个参数集,允许您指定对特定命令调用有效的不同参数“集”。 ParameterSet(除了内部 AllParametersSet - 其中放置未分配参数集的参数)是互斥的。通常,每个参数集都有一个唯一的参数,PowerShell 使用该参数来选择用于参数解析的特定参数集 - 这就是互斥位。如果 PowerShell 无法确定要使用哪个参数集,它将发出错误。在某些情况下,您可以通过使用 [CmdletBinding(DefaultParameterSet="<defaultParameterSetName>")]
来帮助 PowerShell当 PowerShell 无法根据提供的参数和参数计算出参数集时,告诉 PowerShell 使用哪个参数集。
关于c# - Powershell cmdlet 的嵌套参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27463602/