【问题标题】:Call PowerShell script with argument from another Powershell script with bypass使用绕过另一个 Powershell 脚本的参数调用 PowerShell 脚本
【发布时间】:2020-02-14 16:00:07
【问题描述】:

在浏览另一个 ps1 文件时,我需要调用一个 ps1 脚本。新调用不应中断我正在执行的脚本。此外,由于执行策略,我总是这样调用 Powershell 脚本:powershell -ExecutionPolicy Bypass -File file.ps1 -param log_14.txt

我在我的 .ps1 脚本中尝试了以下代码,遗憾的是它不起作用:

    Start-Job PowerShell -Argument "sort.ps1 -file $fileName"

任何想法如何使它工作?

【问题讨论】:

  • 所以这意味着您需要在作业中将参数传递给 ps1 脚本?
  • @WasifHasan 是的,我需要在我正在处理的文件中调用一个带有参数的文件

标签: powershell


【解决方案1】:

试试这个:

$job = Start-Job -ScriptBlock {
  powershell -ExecutionPolicy Bypass -File "filepath.ps1 Param"
}
$job | wait-job | receive-job

【讨论】:

  • The argument 'sort.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter. 这就是我得到的
  • 你需要给出完整的文件路径!
猜你喜欢
  • 2015-07-07
  • 1970-01-01
  • 2011-10-12
  • 1970-01-01
  • 2017-07-12
  • 1970-01-01
  • 2022-01-23
  • 2012-04-13
相关资源
最近更新 更多