即使没有返回错误,也无法通过 powershell 脚本远程安装 chrome

Can't install chrome remotely through powershell script even when no error is returned

我正在尝试在远程服务器上安装 google chrome,但是当我 运行 我的脚本时,没有返回任何错误,但 MSI 不会自动安装软件。该脚本可以在本地运行,但不能远程运行。

这是脚本:

$msi = "MSI path"

Invoke-Command -ComputerName RemoteServer -ScriptBlock {param($msi) Start-Process msiexec.exe -Wait -ArgumentList "/I (MSI Path) /qn /passive"} -ArgumentList $msi

感谢任何帮助或反馈。

我不确定,但我认为您的问题是您将 $msi 用作本地变量和远程变量。牵引选项:

  1. 对于只读变量,您使用 "Using" 关键字

有关详细信息,请参阅 about_remote_variables。如果您只需要从变量中读取值,您可以执行以下操作:

$msi = "MSI path"

Invoke-Command -ComputerName RemoteServer -ScriptBlock { Start-Process msiexec.exe -Wait -ArgumentList "/I $Using:msi /qn /passive"}

这里不需要 Invoke-CommandArgumentList 参数。

  1. 为远程变量添加 _remote 后缀

这只是我在脚本中使用的一种风格,用于区分本地和远程变量。

$msi = "MSI path"

Invoke-Command -ComputerName RemoteServer -ScriptBlock {param($msi_remote) Start-Process msiexec.exe -Wait -ArgumentList "/I $msi_remote /qn /passive"} -ArgumentList  $msi

希望对您有所帮助。

无法使我的脚本运行,因为它是远程服务器上的权限问题。此问题已得到解决。