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



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

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

以下方法应该可以用作写块,您需要为包找到一种执行$logcheck的方法,无论是事件日志还是文件。此样本具有MS Office unistall。

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

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

$scriptUninstallApp = {
Start-Process powershell -Verb runAs {msiexec.exe '/i' "C:Usersfile.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

最新更新