【问题标题】:Can't install chrome remotely through powershell script even when no error is returned即使没有返回错误,也无法通过 powershell 脚本远程安装 chrome
【发布时间】:2018-07-03 03:09:45
【问题描述】:

我正在尝试在远程服务器上安装 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

感谢任何帮助或反馈。

【问题讨论】:

    标签: powershell google-chrome installation windows-installer remote-access


    【解决方案1】:

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

    1. 对于只读变量,您使用“使用”关键字

    详情请见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
    

    希望对您有所帮助。

    【讨论】:

    • 嗨@Moerwald。感谢您的评论。我相信由于我不知道远程服务器权限,该脚本不起作用。我打算尝试其他方法。非常感谢您的反馈,并将在未来考虑到它。
    • @LeeHanyee:如果是远程服务器的权限问题,请回答您自己的问题,并标记为已解决。否则问题一直处于未回答状态,社区成员会尝试回答这个问题,但它已经解决了。
    • 感谢您提供的信息。我对堆栈溢出非常陌生。会注意的。干杯
    【解决方案2】:

    无法让我的脚本正常工作,因为这是远程服务器上的权限问题。已经解决了。

    【讨论】:

      猜你喜欢
      • 2022-08-11
      • 1970-01-01
      • 2014-03-12
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 1970-01-01
      • 2022-10-22
      相关资源
      最近更新 更多