![](/img/trans.png)
[英]Powershell Start-Process msiexec on a remote machine not working
[英]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連接被切斷。
這是我作為解決方法所做的:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.