【发布时间】:2015-06-17 21:54:04
【问题描述】:
我正在编写一个简单的脚本来解析一些事件日志,但是当没有结果或 instanceid 无效时,我需要消除一些错误:
PS C:\> get-eventlog Application -instanceid 1111
Get-EventLog : No matches found
At line:1 char:13
+ get-eventlog <<<< Application -instanceid 1111
+ CategoryInfo : ObjectNotFound: (:) [Get-EventLog], ArgumentException
+ FullyQualifiedErrorId : GetEventLogNoEntriesFound,Microsoft.PowerShell.Commands.GetEventLogCommand
我可以这样做并使其静音,但这也会使其他错误静音:
PS C:\> try { get-eventlog Application -instanceid 1111 -erroraction stop } catch { }
我试过了,但它不起作用:
PS C:\> try { get-eventlog Application -instanceid 1111 -erroraction stop } catch [ObjectNotFound] { }
Unable to find type [ObjectNotFound]: make sure that the assembly containing this type is loaded.
At line:1 char:91
+ try { get-eventlog Application -instanceid 1111 -erroraction stop } catch [ObjectNotFound] <<<< { }
+ CategoryInfo : InvalidOperation: (ObjectNotFound:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
【问题讨论】:
标签: powershell