Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用powershell在远程主机上安装MSI_Powershell_Windows Installer - Fatal编程技术网

使用powershell在远程主机上安装MSI

使用powershell在远程主机上安装MSI,powershell,windows-installer,Powershell,Windows Installer,您好,我无法在远程计算机上的PowerShell中安装file.msi。我可以将file.msi复制到远程计算机,但此作业未执行。仅当PowerShell像管理员一样运行时,此一行程序才起作用: Invoke-Command -Credential(Get-Credential) -ComputerName $computer -ScriptBlock { Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:\Use

您好,我无法在远程计算机上的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'}
}

以下方法应该可以用作scripblock,您需要找到一种方法让包执行
$logcheck
,事件日志或文件。此示例具有MS Office unistall

注意,如果您计划在大量工作站上/定期运行它,我建议将
while($true)
替换为finite for loop或timelapse

我也按原样放置了您的执行脚本,但对我来说,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

尝试将
-Wait
添加到
启动流程
,如下所示:。如果不起作用,我可以发布另一个技巧等待不起作用