2013-03-05 34 views
0

我試圖在遠程計算機上運行以下命令來卸載先前版本的產品,然後再安裝另一個版本。這是使用MsiExec.exe進行卸載。當在遠程計算機上調用啓動進程「MsiExec.exe」時出現PSRemotingTransportException

每當我打電話給啓動過程,該過程實際上運行,產品在遠程計算機上卸載,但我得到下面的異常拋出。如果產品尚未安裝且啓動過程行不運行,則遠程命令可正常工作,不會引發異常。 (即它實際上搜索註冊表,沒有找到產品,並且返回-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      : 
+0

如果在異常之後執行「$ Error [0] .Exception | Format-List * -Force」,您會得到什麼? – 2013-03-06 07:43:57

+0

添加格式化的錯誤發佈。 – TylerOhlsen 2013-03-06 14:41:22

+0

我想我已經發現了這個問題。我認爲我的安裝程序正在重置IIS,從而導致我的Powershell遠程連接被切斷。這聽起來可行嗎? – TylerOhlsen 2013-03-06 19:25:21

回答

1

最佳答案我可以發現,我的卸載是重置IIS,這會導致我的Powershell遠程連接被切斷。

這是我做的一個解決方法:

  1. 從開始處理刪除-Wait並立即關閉PowerShell遠程會話。
  2. Powershell遠程處理會話關閉後,放入啓動 - 睡眠等待卸載完成(猜測卸載需要多長時間並加上一些填充)。
  3. 閱讀卸載日誌文件中的文本「刪除成功或錯誤狀態:XXXX」。其中XXXX是卸載過程的返回碼。
相關問題