別のバージョンをインストールする前に、リモートコンピューターで次のコマンドを実行して、以前のバージョンの製品をアンインストールしようとしています。これは、MsiExec.exeを使用してアンインストールしています。
Start-Processを呼び出すと、プロセスが実際に実行され、製品がリモートコンピューターにアンインストールされますが、以下の例外がスローされます。製品がまだインストールされておらず、Start-Process行が実行されていない場合、remoteコマンドは例外をスローせずに正常に機能します。(つまり、実際にレジストリを検索し、製品を検出せず、例外をスローせずに-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 :