0

我需要帮助隐藏当 Powershell 找不到正在运行的 Excel 实例(或以某种方式绕过它的方法)时发生的以下错误消息:

Get-Process:找不到名为“excel”的进程。验证进程名称并再次调用 cmdlet。在 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 回答