【问题标题】:Get result from a remote call to msiexec using Powershell使用 Powershell 从远程调用 msiexec 中获取结果
【发布时间】:2013-02-07 16:06:43
【问题描述】:

我在 Win 2008r2 上使用 Powershell 对 msiexec 进行远程调用,如下所示:

Invoke-Command -session $Session -ScriptBlock{param($arguments) start-process -FilePath "msiexec.exe" -Wait $arguments } -Argument $arguments

目前我正在使用 if(!$?) 检查是否成功,但这并不好,因为我刚刚看到 msiexec 进程抛出 1638 错误(因为该应用程序已经安装在远程服务器上)但是值美元?是真的。

谁能告诉我如何捕获远程服务器上的 msiexec 返回的 1638 代码或其他任何代码?

谢谢,罗伯。

【问题讨论】:

标签: powershell-2.0 powershell-remoting


【解决方案1】:

这是一种非常老套的方法,但我通过使用类似于全局的变量 $script:functionexitcode 解决了这个问题,我将使用 Start 分配 msiexec.exe 中的 .ErrorCode 的值-进程。

然后在 PowerShell 脚本的主要部分,我将测试该值 if ($functionexitcode -eq 0)。

以下是与 Start-Process 非常相似的安装场景的完整 sn-p:

# Start MSP upgrade to UR

$upgrade = (Start-Process -Filepath $msiexecpath -ArgumentList $argumentlist_BEGIN$argumentlist_MSP$argumentlist_END -PassThru -Wait -ErrorAction Stop)

if ($upgrade.ExitCode -eq 0) {

    Write-Host "Upgrade successful. Error code:" $upgrade.ExitCode `

    "`nUpgrade logfile location: " $workingdirectory\$msi_logfile_upgrade

    $script:FunctionExitCode = $upgrade.ExitCode

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-14
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 2016-03-21
    • 2013-08-19
    • 2019-02-25
    相关资源
    最近更新 更多