使用PowerShell在远程服务器上安装可执行文件(.msi/.exe)时会出错



i有一个可执行文件(.msi.exe)的列表,我必须在某些远程服务器(在同一域中)使用PowerShell脚本安装 ssilesly 。首先,我将所有程序从本地服务器复制到远程服务器。接下来,我将尝试将所有这些程序逐一安装到远程服务器。为此,我使用以下代码:

Copy-Item -Path "C:pathtosoftwares*" -Destination "C:pathtodestination"  # this is copying all softwares on destination path
$destItem = Get-ChildItem -Path "C:pathtodestination"
foreach($software in $destItem)
{
    $setup = Invoke-Command -ComputerName <computer> -ScriptBlock {$temp=Start-Process "C:pathto$software" -ArgumentList "/s" -Wait -PassThrough;$Temp}
}

问题是:当我运行此脚本时,我会收到以下错误:

[172.xx.xx.xxx]连接到远程服务器172.xx.xx.xxx失败了以下错误消息:winrm client 无法处理请求。默认身份验证可以在以下条件下与IP地址一起使用: 运输是https,或者目的地在TrustedHosts列表中,并提供了明确的凭据。使用 winrm.cmd配置TrustedHosts。请注意,TrustedHosts列表中的计算机可能没有得到认证。更多 有关如何设置TrustedHosts运行以下命令的信息:WINRM帮助配置。有关更多信息,请参阅 关于_remote_troubleshooting帮助主题。
categoryInfo:OpenError:(172.xx.xx.xxx:string)[],psremotingtransportException
完全qualififiedErrid:cossessionStateStateBroken

i在本地机器上运行命令winrm quickconfig,并得到了此结果:

WinRM service is already running on this machine.
WinRM is already set up for remote management on this computer.

从远程服务器中获得此输出:

WinRm already is set up to recieve requests on this machine.
WinRm already is set up for remote management on this machine.
  • Windows版本:Windows Server 2012R2
  • PS版本:4

问题是:如何解决此问题并可以在远程服务器上安装可执行文件?

您可以尝试将远程计算机放入受信任的主机列表中:

  • 查看TrustedHosts的列表 get-item wsman:localhostClientTrustedHosts

  • 将所有计算机(小心!)添加到TrustedHost的列表中 set-item wsman:localhostClientTrustedHosts -value *

  • 在受信任的主机列表中添加带有特定IP地址的计算机 set-item wsman:localhostClientTrustedHosts -value 192.168.0.10

检查马特·沃克(Matt Wrock)关于在Windows上安装软件的文章:

http://www.hurryupandwait.io/blog/safely-running-windows-automation-automation--that-tyty-typy-typy-fail-over-over-winrm-or-powershell-oremothell

在他的BoxStarter库中,他通过使用Invoke-fromTask命令将命令包裹在计划的任务中来解决此问题:

Invoke-FromTask @"
    Start-Process "$env:tempnet45.exe" -verb runas -wait `
      -argumentList "/quiet /norestart /log $env:tempnet45.log"
"@

最新更新