如何将开关参数传递给另一个 PowerShell 脚本? [英] How to pass a switch parameter to another PowerShell script?

查看:57
本文介绍了如何将开关参数传递给另一个 PowerShell 脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 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..elsecase 语句?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆