我希望能够具有相同参数的多种形式,例如:
param(
[string]$p or $path = "C:\",
[string]$f or $filter = "*.txt",
[switch]$o or $overwrite
)
但我不确定该怎么做。大多数情况下,您只能选择一个(例如,仅$ p或仅$ path)。同一变量/参数可以使用多个名称吗?
最佳答案
像这样:
param(
[Alias('p')]
[string]$path = "C:\",
[Alias('f')]
[string]$filter = "*.txt",
[Alias('o')]
[switch]$overwrite
)
注意,您也可以有多个别名:
[Alias('p','thepath')]
关于parsing - 如何在Powershell中处理参数的多个选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14268054/