我需要帮助隐藏当 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 $_}