是否可以将另一个脚本中的powershell脚本作为变量调用?

时间:2013-02-04 18:27:45

标签: powershell parameters parameter-passing powershell-v2.0

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

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

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

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

1 个答案:

答案 0 :(得分:5)

听起来你需要使用-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.