使用 System.Management.Automation,您可以在 C# 中创建自定义 PSCmdlet。 现在,如果您像这样创建 bool 参数:
[Parameter()]
public bool ShowDefinition { get; set; }
您必须像这样调用 cmdlet:
PS> Get-CustomValues -ShowDefinition 1
但我想在不将值传递给 -ShowDefinition 的情况下调用它。与 -Debug 的工作方式相同。 像这样:
PS> Get-CustomValues -ShowDefinition
我该怎么做?
最佳答案
好的,我找到了答案。
您必须使用 SwitchParameter。
[Parameter]
public SwitchParameter ShowDefinition { get; set; }
protected override void ProcessRecord(){
if(ShowDefinition.ToBool()){
...
}
}
关于c# - 如何使 PSCmdlet bool 参数像标志一样工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30755341/