0

Powershell が実行中の Excel インスタンスを検出できない場合 (または何らかの方法でそれを回避する手段) に発生する以下のエラー メッセージを非表示にする方法を教えてください。

Get-Process : "excel" という名前のプロセスが見つかりません。プロセス名を確認し、コマンドレットを再度呼び出します。run.ps1:3 で char:24 + $before = @(get-process <<<< Excel | %{$_.Id} ) + CategoryInfo : ObjectNotFound: (excel:String) [Get-Process], ProcessCommandException + FullyQualifiedErrorId : NoProcessFoundForGivenName,Microsoft.PowerShell.Commands.GetProcessCommand

私のコードの3-5行目は次のとおりです。

$before = @(get-process excel | %{$_.Id} ) 
$excel=new-object -com excel.application
$excelId = get-process excel | %{$_.Id} | ?{$before -notcontains $_}
4

1 に答える 1

3

多分あなたは次のことができますか?

Get-Process Excel -ErrorAction SilentlyContinue | %{ $_.Id }

それともこれ?

Get-Process | ?{ $_.name -eq "excel" } | %{ $_.Id }
于 2013-10-27T04:57:21.287 に答える