gpt4 book ai didi

PowerShell参数集: Require either A or B to be set

转载 作者:行者123 更新时间:2023-12-04 01:15:04 25 4
gpt4 key购买 nike

是否有一种简单的方法来设置允许同时指定A或B但不能同时指定两者的参数集?

例如。我的脚本将接受:

.\SimpleScript.ps1 -A "str1" -X 1 -Y 2 -Z 3

或者
.\SimpleScript.ps1 -B "str2" -X 1 -Y 2 -Z 3

但不是:
.\SimpleScript.ps1 -A "str1" -B "str2" -X 1 -Y 2 -Z 3

最佳答案

您可以编写CmdLet并使用Parameter sets

看看About Functions Advanced Parameters的基本文档

Param
(
[parameter(Mandatory=$true,
ParameterSetName="WithA")]
[String]
$A,

[parameter(Mandatory=$true,
ParameterSetName="WithB")]
[String]
$B,

[parameter(Mandatory=$true)]
[Int]
$X
...
)

关于PowerShell参数集: Require either A or B to be set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45303629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com