使用powershell在远程主机上安装MSI
您好,我无法在远程计算机上的PowerShell中安装使用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
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
添加到启动流程
,如下所示:。如果不起作用,我可以发布另一个技巧等待不起作用