如何将开关参数传递给另一个 PowerShell 脚本? [英] How to pass a switch parameter to another PowerShell script?
问题描述
我有两个 PowerShell 脚本,它们具有开关参数:
I have two PowerShell scripts, which have switch parameters:
compile-tool1.ps1:
[CmdletBinding()]
param(
[switch]$VHDL2008
)
Write-Host "VHDL-2008 is enabled: $VHDL2008"
compile.ps1:
[CmdletBinding()]
param(
[switch]$VHDL2008
)
if (-not $VHDL2008)
{ compile-tool1.ps1 }
else
{ compile-tool1.ps1 -VHDL2008 }
如何将 switch 参数传递给另一个 PowerShell 脚本,而无需编写大的 if..then..else
或 case
语句?
How can I pass a switch parameter to another PowerShell script, without writing big if..then..else
or case
statements?
我不想将compile-tool1.ps1
的参数$VHDL2008
转换成bool
类型,因为,两个脚本都是前端脚本(由用户使用).后者是多个 compile-tool*.ps1
脚本的高级包装器.
I don't want to convert the parameter $VHDL2008
of compile-tool1.ps1
to type bool
, because, both scripts are front-end scripts (used by users). The latter one is a high-level wrapper for multiple compile-tool*.ps1
scripts.
推荐答案
您可以使用 colon-syntax 在开关上指定 $true
或 $false
:
You can specify $true
or $false
on a switch using the colon-syntax:
compile-tool1.ps1 -VHDL2008:$true
compile-tool1.ps1 -VHDL2008:$false
所以只需传递实际值:
compile-tool1.ps1 -VHDL2008:$VHDL2008
这篇关于如何将开关参数传递给另一个 PowerShell 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!