c# - Powershell cmdlet 的嵌套参数

标签 c# powershell

新手问题。

如何声明 Powershell cmdlet 的嵌套参数?我想要一个看起来像这样的 cmdlet。

New-FootballTeam 
[-Defenders [[-LeftBack] <string>] [[-RightBack] <string>] ]
[-Midfielders [[-LeftWing] <string>] [[-RightWing] <string>] [[-CentreMidfield] <string>] ] 

我尝试使用 ParameterSetName 参数将 DefendersMidfielders 下的参数组合在一起。但是,当我执行 help New-FootballTeam 时,DefendersMidfielders 标签不会显示,我看到类似这样的内容。

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/

相关文章:

powershell - 移动项目 : There is not enough space on the disk

windows - 进程 block 在 Graphics.DrawString 中不起作用

regex - 通过正则表达式从行中分割特定字符串

c# - 我怎样才能把函数放在其他cs文件中?

c# - 如何使用内连接将两个 DataTable 连接在一起

c# - API 在代码中返回有效的 JSON,但在浏览器中返回无效的 JSON

powershell - 想要使用Powershell查询远程PC的正常运行时间

powershell - vagrant powershell 翻译缺失 : en. vagrant_winrm.errors.winrm_not_ready

c# - 如何在 ASP.NET GridView 中添加按钮/链接的 href

c# - 如何使用 CHARACTER * 50 类型的参数将参数从 C# 传递到 FORTRAN?