【问题标题】:Is it possible to call a powershell script within another script as a variable?是否可以在另一个脚本中调用 powershell 脚本作为变量?
【发布时间】:2013-01-19 12:38:51
【问题描述】:

我有一个 Powershell 脚本,用户将脚本作为参数传入其中。传入之后,我无法使用 $scriptvariable 调用脚本。当需要从变量调用一个脚本时,有什么方法可以从另一个 Powershell 脚本中调用一个 Powershell 脚本。

param(
  [string]hostval,
  [string]$scriptpath
)

Invoke-Command -Computer $hostval -Scriptblock { $scriptpath } -credential $cred

这不起作用,我不确定我想要的是否可能。是否有我可以使用的参数类型(例如:[script]$scriptpath)以便可以从 $scriptpath 调用脚本?

【问题讨论】:

    标签: powershell parameters parameter-passing powershell-2.0


    【解决方案1】:

    听起来你需要使用 -FilePath 参数,而不是 -Scriptblock:

    -FilePath <String>
        Runs the specified local script on one or more remote computers. Enter the path and file name of the script, or pipe a script path to Invoke-Command. The script must reside on the local computer or in a directory that the local computer can access. Use the ArgumentList parameter to specify the values of parameters in the script.
    

    【讨论】:

      猜你喜欢
      • 2015-07-07
      • 1970-01-01
      • 2021-08-15
      • 2019-07-04
      • 2017-07-12
      • 2022-01-23
      • 2011-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多