TylerOhlsen
TylerOhlsen

Reputation: 5578

PSRemotingTransportException when calling Start-Process "MsiExec.exe" on remote machine

I am trying to run the following command on a remote computer to uninstall the previous version of a product before I install another version. This is uninstalling using MsiExec.exe.

Whenever I call Start-Process, the process actually runs and the product is uninstalled on the remote computer, but I get the below exception thrown. If the product is not already installed and the Start-Process line does not run, the remote command works fine with no thrown exception. (i.e. it actually searches the registry, does not find the product, and returns -1 without throwing an exception) The problem only arises when Start-Process is called.

Here's my script code...

$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);

And the thrown exception...

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]

And the formatted error...

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                      :

Upvotes: 1

Views: 5172

Answers (1)

TylerOhlsen
TylerOhlsen

Reputation: 5578

The best answer I could find is that my uninstall is resetting IIS, which causes my Powershell Remoting connection to be severed.

This is what I did as a work around:

  1. Remove the -Wait from Start-Process and immediately close the Powershell Remoting session.
  2. After the Powershell Remoting session is closed, put in a Start-Sleep to wait for the uninstall to finish (with a guess at how long the uninstall will take plus some padding).
  3. Read the uninstall's log file for the text "Removal success or error status: XXXX." Where XXXX is the return code of the uninstall process.

Upvotes: 2

Related Questions