powershell - Catching Get-EventLog errors -
I am writing a simple script to parse some event log, but I do not have an error, or if instanceid Invalid:
PS: \ & gt; Get-eventlog application -instanceid 1111 Get-EventLog: No matches found on line: 1 character: 13+ receiving-event log & lt; & Lt; & Lt; & Lt; Application -instanceid 1111 + Series information: ObjectNotFound: (:) [Get-EventLog], ArgumentException + FullyQualifiedErrorId: GetEventLogNoEntriesFound, Microsoft.Power.Shell.Commands.GetEventLogCommand
I can do And silence it, but it will also silence other errors:
PS: \ & gt; Try {get-eventlog application -instanceid 1111 -erroraction stop} catch {}
I tried it but it does not work:
PS C: \ & gt; {Hold Get-eventlog application -instanceid 1111 -erroraction stop} [ObjectNotFound] {} type [ObjectNotFound] thus unable to find: Make sure that this type has been loaded on the assembly. In line: 1 character: 91 + Try {get-eventlog Application-Instant 1111-Terrorism Prevention} Hold [Object Notfans] & lt; & Lt; & Lt; & Lt; {} + Series Info: Amanyopreshn: (object Notfound: String) [], runtime Akspasn + Fulkwaiclaijd error id: type Notfound
you -arraakshn Sililikantinu
after that you can use and you can check your $ errors
variable,
$ error [0]
It always contains the last error object.
Comments
Post a Comment