我正在尝试在远程计算机上运行以下命令来卸载以前版本的产品,然后再安装另一个版本。这是使用 MsiExec.exe 进行卸载。
每当我调用 Start-Process 时,该进程实际上会运行并且产品会在远程计算机上卸载,但我会抛出以下异常。如果该产品尚未安装且 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 :