powershell - 使用 powershell 在远程主机上安装 MSI
问题描述
您好,我无法file.msi
在远程计算机上的 PowerShell 中安装。我可以复制file.msi
到远程计算机,但这项工作没有执行。仅当 PowerShell 像管理员一样运行时,此单行程序才有效:
Invoke-Command -Credential(Get-Credential) -ComputerName $computer -ScriptBlock {
Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:\Users\file.msi", '/passive'}
}
解决方案
以下方法应该可以用作脚本块,您需要找到一种方法让您的包执行$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
推荐阅读
- javascript - React 中未处理的 Promise Rejection
- nginx - Ingress 和 nginx 配置问题
- elasticsearch - grafana 升级后 Cloudwatch 数据源无法正常工作
- sql-server - 如何在不使用反向函数的情况下反转 SQL Server 中的字符串?
- python - 为什么我不能使用 Gurobi 获得线性编程代码的结果?
- spring-boot - NoSuchMethodException QueryDSL 与 Spring Boot 和 Spring Data Mongo
- java - React native - 如何修复 Java.lang Double 无法转换为 java.lang.Boolean
- java - Eclipse 氧气/光子与 openjdk 11 和弹簧靴
- html - 无法将 Img 与文本相对且大小相同
- javascript - 当用户第二次点击按钮时,UI 不会在 React 中重新渲染