在远程计算机上调用Start-Process“MsiExec.exe”时出现PSRemotingTransportException

时间:2013-03-05 23:13:20

标签: powershell windows-installer powershell-remoting

我尝试在远程计算机上运行以下命令以在安装其他版本之前卸载以前版本的产品。这是使用MsiExec.exe卸载。

每当我调用Start-Process时,该进程实际运行并且远程计算机上的产品已卸载,但我抛出了以下异常。如果尚未安装产品且Start-Process行未运行,则remote命令正常工作,没有抛出异常。 (即它实际上搜索注册表,找不到产品,并返回-1而不抛出异常)只有在调用Start-Process时才会出现问题。

这是我的脚本代码......

$UninstallScriptBlock = {
    param ( [string]$InstallerProductName )

    $ErrorActionPreference = "Stop";

    $UninstallRegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";
    $ProductCode = Get-ChildItem -Path $UninstallRegPath | foreach { if ($_.GetValue("DisplayName") -eq $InstallerProductName) { [System.IO.Path]::GetFileName($_); } }
    if ([string]::IsNullOrEmpty($ProductCode))
    {
        $UninstallRegPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall";
        $ProductCode = Get-ChildItem -Path $UninstallRegPath | foreach { if ($_.GetValue("DisplayName") -eq $InstallerProductName) { [System.IO.Path]::GetFileName($_); } }
    }
    if ([string]::IsNullOrEmpty($ProductCode))
    {
        return -1;
    }

    $Process = Start-Process -Wait -Passthru -FilePath "MsiExec.exe" -ArgumentList "/X", $ProductCode, "/qn";
    return $Process.ExitCode;
}

[int]$UninstallReturnCode = Invoke-Command -ComputerName $Server -ScriptBlock $UninstallScriptBlock -ArgumentList $InstallerProductName -SessionOption (New-PSSessionOption -OperationTimeout 0);

抛出的异常......

Processing data for a remote command failed with the following error message: The I/O operation has been aborted because of either a thread exit or an application request. For more information, see the about_Remote_Troubleshooting Help topic.
At [Undisclosed]
+     [int]$UninstallReturnCode = Invoke-Command -ComputerName $Server -ScriptBloc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: ([UndisclosedServerName]:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : JobFailure
+ PSComputerName        : [UndisclosedServerName]

格式化错误......

ErrorCode                   : 995
TransportMessage            : The I/O operation has been aborted because of either a thread exit or an application request.

ErrorRecord                 : Processing data for a remote command failed with the following error message: The I/O
                              operation has been aborted because of either a thread exit or an application request. For
                              more information, see the about_Remote_Troubleshooting Help topic.
StackTrace                  :
WasThrownFromThrowStatement : False
Message                     : Processing data for a remote command failed with the following error message: The I/O
                              operation has been aborted because of either a thread exit or an application request. For
                              more information, see the about_Remote_Troubleshooting Help topic.
Data                        : {}
InnerException              :
TargetSite                  :
HelpLink                    :
Source                      :

1 个答案:

答案 0 :(得分:1)

我能找到的最佳答案是我的卸载正在重置IIS,这会导致我的Powershell Remoting连接被切断。

这就是我做的工作:

  1. 从Start-Process中删除-Wait并立即关闭Powershell Remoting会话。
  2. 关闭Powershell Remoting会话后,进入Start-Sleep等待卸载完成(猜测卸载需要多长时间以及一些填充)。
  3. 阅读卸载的日志文件,了解文本"删除成功或错误状态:XXXX。"其中XXXX是卸载过程的返回码。
相关问题