簡體   English   中英

在遠程計算機上調用啟動過程“ MsiExec.exe”時,PSRemotingTransportException

[英]PSRemotingTransportException when calling Start-Process “MsiExec.exe” on remote machine

我試圖在遠程計算機上運行以下命令以卸載產品的先前版本,然后再安裝其他版本。 這是使用MsiExec.exe卸載的。

每當我調用Start-Process時,該進程實際上就會運行並且該產品會在遠程計算機上卸載,但是會引發以下異常。 如果尚未安裝產品,並且“啟動進程”行未運行,則遠程命令可以正常運行,不會引發異常。 (即,它實際上搜索注冊表,未找到產品,並返回-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                      :

我能找到的最佳答案是,我的卸載正在重置IIS,這將導致Powershell Remoting連接被切斷。

這是我作為解決方法所做的:

  1. 從啟動過程中刪除-Wait,然后立即關閉Powershell Remoting會話。
  2. 關閉Powershell Remoting會話后,放入Start-Sleep以等待卸載完成(猜測卸載將花費多長時間以及一些填充)。
  3. 閱讀卸載日志文件中的文本“刪除成功或錯誤狀態:XXXX”。 其中XXXX是卸載過程的返回碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM