Reputation: 5578
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
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:
Upvotes: 2