【问题标题】:Pass custom Parameters for & call为 & 调用传递自定义参数
【发布时间】:2018-02-27 05:23:03
【问题描述】:

在 Powershell 中,我正在调用自定义脚本:

 &  C:\test.ps1 

我想将自定义参数传递给该脚本。我正在尝试 ArgumentList。但我认为这只涉及预定义的参数。

 &  C:\test.ps1 -ArgumentList "Something"

我不确定如何将我自己的自定义变量传递给我调用的另一个脚本...

【问题讨论】:

标签: powershell


【解决方案1】:

在这种情况下,您有两种选择:

& C:\Test.ps1 -Switch1 -arg 'this is an arg'

或者Start-Process cmdlet:

Start-Process -FilePath 'C:\Test.ps1' -ArgumentList @('-Switch1','-arg','this is an arg')

但这引出了一个问题:为什么要调用 PowerShell 脚本而不是将其模块化为函数或模块以导入您打算使用的脚本?

【讨论】:

  • 如何在 Test.ps1 脚本中调用它。会是 $Switch1 吗?
  • @TakafuKeyomama 你能澄清一下你想做什么吗?
  • @TakafuKeyomama 在第一个示例中,您需要在Test.ps1 中输入declare the parameters。其次,您可以通过$args 访问它们
猜你喜欢
  • 1970-01-01
  • 2016-08-04
  • 1970-01-01
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 1970-01-01
  • 2013-12-11
  • 2012-12-08
相关资源
最近更新 更多