【问题标题】:Invoke-Command doesn't run the bat fileInvoke-Command 不运行 bat 文件
【发布时间】:2022-01-18 02:00:51
【问题描述】:

我正在为无人值守安装推出一个脚本,我为 Office 2019 安装构建了一个小型 .bat,当我运行它时它运行良好,但是当我通过 PowerShell 脚本调用它时,安装不运行。

有什么想法吗?

这是部分代码

Invoke-Command -ScriptBlock {Start-Process -FilePath "c:\temp\Office2019\Install-32.bat" -ArgumentList "--quiet" -Verb RunAs -Wait}

.bat 文件

setup.exe /configure configuration-x86.xml

Office 配置文件

  <Add OfficeClientEdition="32">
    <Product ID="ProPlus2019Volume" PIDKEY="MYKEY">
      <Language ID="en-us" />
    </Product>
  </Add>
  <Display Level="None" AcceptEULA="TRUE"/>
  <Property Name="AUTOACTIVATE" Value="1"/>
</Configuration>

非常感谢您的建议。

【问题讨论】:

  • 我认为您不能使用参数列表来调用 bat 文件。您必须在 bat 文件本身中指定进行静默安装。或者您可以直接调用setup.exe -argumentlist “/configure $xmlfile /q” -wait,而不是使用 bat 文件

标签: powershell batch-file


【解决方案1】:

Bat 文件只能由 OS shell 解释,即 cmd.exe。您的文件路径需要更改如下:

cmd.exe /c c:\temp\Office2019\Install-32.bat

Powershell 不会解释 bat 文件,它只运行 exe 文件和命令。

【讨论】:

  • 您好,Digger,感谢您的回复。
  • 感谢您的评论。事实上它已经解决了这个问题。这是因为我需要定义执行浴文件的工作目录,最后这句话是这样的: { Invoke-Command -ScriptBlock {Start-Process -WorkingDirectory "c:\temp\Office2019\" - FilePath "c:\temp\Office2019\Install-32.bat" -Wait -Verb RunAs} } 非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多