【问题标题】:Install MSI on remote host using powershell使用 powershell 在远程主机上安装 MSI
【发布时间】:2021-05-12 20:33:36
【问题描述】:

您好,我无法在远程计算机上的 PowerShell 中安装 file.msi。我可以将file.msi 复制到远程计算机,但此作业未执行。这种单行只在 PowerShell 像管理员一样运行时才有效:

Invoke-Command -Credential(Get-Credential) -ComputerName $computer -ScriptBlock {
   Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:\Users\file.msi", '/passive'}
}

【问题讨论】:

标签: powershell windows-installer


【解决方案1】:

以下方法应该可以用作脚本块,您需要为您的包找到一种方法来执行$logcheck,无论是事件日志还是文件。此示例有 MS Office 未安装。

注意,如果您打算/定期在大量工作站上运行它,我建议将 while($true) 替换为有限 for 循环或延时。

我还按原样放置了您的执行脚本,但对我来说 msiexec.exe 无需执行 PowerShell 即可工作

$scriptUninstallApp = {
  Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:\Users\file.msi", '/passive'}
  $logcheck = ""
  while($true)
  {   
    if($logcheck -match "Windows Installer removed the product")
    {
      return
    }
    else
    {
      start-sleep -Seconds 1
      [string]$logcheck = get-eventlog -logname application -newest 10 -Source msiinstaller | ?{$_.message -like "*Windows Installer removed the product. Product Name: Microsoft Office*"} | select -ExpandProperty message
    }
  }
}

Invoke-Command -Credential(Get-Credential) -ComputerName $computer -ScriptBlock $scriptUninstallApp

【讨论】:

    猜你喜欢
    • 2015-07-06
    • 1970-01-01
    • 1970-01-01
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 2018-01-12
    • 1970-01-01
    相关资源
    最近更新 更多