{"id":1261,"date":"2014-06-03T00:01:00","date_gmt":"2014-06-03T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2014\/06\/03\/use-filterhashtable-to-filter-event-log-with-powershell\/"},"modified":"2014-06-03T00:01:00","modified_gmt":"2014-06-03T00:01:00","slug":"use-filterhashtable-to-filter-event-log-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-filterhashtable-to-filter-event-log-with-powershell\/","title":{"rendered":"Use FilterHashTable to Filter Event Log with PowerShell"},"content":{"rendered":"<p><b>Summary<\/b>: Microsoft Scripting Guy, Ed Wilson, talks about using a filter hash table to filter the event log with Windows PowerShell.<\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. The weather here in Charlotte, North Carolina has turned hot and humid. As a result, the Scripting Wife decided to migrate north for a while. Actually, she is attending a conference in Cincinnati, Ohio. This has given me a bit of extra time to play around with Windows PowerShell and to work on my laptop.<\/p>\n<p>The most powerful way to filter event and diagnostic logs by using Windows PowerShell is to use the <b>Get-WinEvent cmdlet<\/b>. Introduced in Windows PowerShell&nbsp;2.0, the <b>Get-WinEvent<\/b> cmdlet is not new technology. But most people do not use the <b>Get-WinEvent<\/b> cmdlet because it seems to be more difficult to use. The <b>Get-EventLog<\/b> cmdlet that I used yesterday is easy-to-use, and for a lot of things, it works just fine.<\/p>\n<p>But <b>Get-WinEvent<\/b> has several ways to filter the left side of the pipeline. When working with large logs, grabbing everything and sending it down the pipeline to a <b>Where-Object<\/b> cmdlet is not the most efficient thing to do. It fact, it can be downright slow. An example of this sort of slow command is shown here:<\/p>\n<p style=\"margin-left:30px\">Get-EventLog -LogName application | where source -match &#039;defrag&#039;<\/p>\n<h2>Get-WinEvent the easy way<\/h2>\n<p>The easiest way to perform powerful queries by using <b>the Get-WinEvent<\/b> cmdlet is to use the <b>FilterHashTable<\/b> parameter. As the parameter name might imply, it accepts a hash table as a filter. A hash table is made up of key\/value pairs. Therefore, the trick is to know the permissible key names and what an acceptable value for that key might look like. Here is a table that shows the key names, the data type it accepts, and whether it will accept a wildcard character for that data value.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"margin-left:30px\">\n<tbody>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p><b>Key name<\/b><\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p><b>Value data type<\/b><\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p><b>Accepts wildcard characters?<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;LogName<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;String[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;ProviderName<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;String[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;Yes<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;Path<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;String[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;Keywords<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;Long[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;ID<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;Int32[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;Level<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;Int32[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;StartTime<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;DateTime&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;EndTime<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;DataTime&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;UserID<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;SID&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;Data<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;String[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"224\" valign=\"top\">\n<p>&nbsp;*<\/p>\n<\/td>\n<td width=\"220\" valign=\"top\">\n<p>&nbsp;&lt;String[]&gt;<\/p>\n<\/td>\n<td width=\"194\" valign=\"top\">\n<p>&nbsp;No<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>One thing I like to do when I build a query using <b>Get-Winevent<\/b> is to take it a step at a time. I begin with the <b>LogName<\/b>. As shown here, this first query is the same as typing <b>Get-EventLog &ndash;LogName<\/b> <b>Application<\/b>:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;}<\/p>\n<p>The next thing I want to specify (I do not have to use the order that is presented in my previous table) is the <b>ProviderName<\/b>. This example returns entries generated by the <b>.NET RunTime <\/b>source, in the <b>Application<\/b> log:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;; providername=&#039;.Net Runtime&#039; }<\/p>\n<p>The <b>ProviderName<\/b> is the name that appears in the <b>Source<\/b> field in the Event Viewer. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-3-14-01.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-3-14-01.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>I use the <b>&ndash;path<\/b> parameter when I am working with archived event logs. I wrote a good blog post about that: <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/use-powershell-to-parse-saved-event-logs-for-errors\/\" target=\"_blank\">Use PowerShell to Parse Saved Event Logs for Errors<\/a>.<\/p>\n<p>In my hash table, the next key is the <b>Keywords<\/b> key name. This sounds like you would be able to use keywords to filter out event log events. But the <b>Data Type<\/b> field holds an array made up of the <b>[long] <\/b>value type, and a <b>[long]<\/b> value type holds a really large number.&nbsp;Here is the maximum value:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; [long]::MaxValue<\/p>\n<p style=\"margin-left:30px\">9223372036854775807<\/p>\n<p>Therefore, what Windows PowerShell wants is a number, not a keyword (such as <b>Security<\/b>). I can use the GUI to see what permissible keywords are feasible. This is shown here:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-3-14-02.png\"><img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/hsg-6-3-14-02.png\" alt=\"Image of menu\" title=\"Image of menu\" \/><\/a><\/p>\n<p>The problem is that when I attempt to use one of these keywords, I get an error message. This is because these are string values, and not long numbers. So when I have a potential list of keywords that have associated numeric values, I think enumeration. In fact, these are the <b>StandardEventKeywords<\/b> enumeration, as shown here:<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; [System.Diagnostics.Eventing.Reader.StandardEventKeywords] | gm -s -MemberType property<\/p>\n<p style=\"margin-left:30px\">&nbsp;&nbsp; TypeName: System.Diagnostics.Eventing.Reader.StandardEventKeywords<\/p>\n<p style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MemberType Definition<\/p>\n<p style=\"margin-left:30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8212;&#8212;- &#8212;&#8212;&#8212;-<\/p>\n<p style=\"margin-left:30px\">AuditFailure&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">AuditSuccess&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">CorrelationHint&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">CorrelationHint2 Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">EventLogClassic&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">None&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">ResponseTime&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">Sqm&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">WdiContext&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p style=\"margin-left:30px\">WdiDiagnostic&nbsp;&nbsp;&nbsp; Property&nbsp;&nbsp; static System.Diagnostics.Eventing.Reader.StandardEventKey&#8230;<\/p>\n<p>This enumeration is documented on MSDN (<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.diagnostics.eventing.reader.standardeventkeywords.aspx\" target=\"_blank\">StandardEventKeywords Enumeration<\/a>), but it does not display the enumeration numeric values. For a function that will do this, take a look at <a href=\"\/b\/heyscriptingguy\/archive\/tags\/enum\/\" target=\"_blank\">my series of blog posts about enumerations<\/a>, and in particular, read <a href=\"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-weekend-scripter-enumerations-and-values\/\" target=\"_blank\">Enumerations and Values<\/a>. In fact, my <b>Get-EnumAndValues<\/b> function is so helpful that it is a function I have in my <a href=\"http:\/\/social.technet.microsoft.com\/Search\/en-US?query=profiles&amp;rn=Hey,%20Scripting%20Guy!%20Blog&amp;rq=site:blogs.technet.com\/b\/heyscriptingguy\/&amp;beta=0&amp;ac=2\" target=\"_blank\">Windows PowerShell profile<\/a>. When I use the <b>Get-EnumAndValues<\/b> function, I retrieve the following results:<\/p>\n<p style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">&#8212;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8212;&#8211;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">AuditFailure&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 4503599627370496&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">AuditSuccess&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 9007199254740992&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">CorrelationHint2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 18014398509481984&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">EventLogClassic&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;36028797018963968&nbsp;&nbsp;&nbsp;&nbsp;&n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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">ResponseTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 281474976710656&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p style=\"margin-left:30px\">None&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p>Now the query looks like the following (this is a one-line command that is wrapped for readability):<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;; providername=&#039;.Net Runtime&#039;; keywords=36028797018963968}<\/p>\n<p>Because this is an enumeration, I can also use the actual enumeration static property, but I have to convert it to the value by calling the <b>value__<\/b> property, and not to the returned string. To do this, I might use the following script:<\/p>\n<p style=\"margin-left:30px\">$c = [System.Diagnostics.Eventing.Reader.StandardEventKeywords]::EventLogClassic<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;; providername=&#039;.Net Runtime&#039;; keywords=$c.value__}<\/p>\n<p>As I have been running my commands, I have been getting increasingly shorter outputs of event log records. From that list, I select the particular event ID, which in <b>FilterHashTable<\/b> becomes the keyword ID. This command is shown here:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;; providername=&#039;.Net Runtime&#039;<\/p>\n<p style=\"margin-left:30px\">; keywords=36028797018963968; ID=1023}<\/p>\n<p>I now decide that I want to filter out only the errors. This is the <b>Level<\/b> property. But when I use the command shown here, it generates an error message.<\/p>\n<p style=\"margin-left:30px\">PS C:\\&gt; Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;; providername=&#039;.Net Runtime&#039;<\/p>\n<p style=\"margin-left:30px\">; keywords=36028797018963968; ID=1023; level=&#039;error&#039;}<\/p>\n<p>I go back to my has table, and sure enough, I see that <b>Level<\/b> needs an <b>Int32<\/b>, or an array of Int32s. So it wants another number, and not the standard error, warning, information that I am used to using. This smells like another enumeration.<\/p>\n<p>I look back at the MSDN page I had open for the previous enumeration, and I discover that there is a <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.diagnostics.eventing.reader.standardeventlevel(v=vs.110).aspx\" target=\"_blank\">StandardEventLevel Enumeration<\/a>. It works the same way as the previous enumeration. I can create the class, use the <b>Get-Member<\/b> with <b>&ndash;Static<\/b>, and use my enumeration value function. Here are the enumeration member names and their associated values:<\/p>\n<p style=\"margin-left:30px\">Name&nbsp;&nbsp;&nbsp;&nbsp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nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/p>\n<p>Armed with this information, I know that an error is level 2. So here is the modified command:<\/p>\n<p style=\"margin-left:30px\">Get-WinEvent -FilterHashtable @{logname=&#039;application&#039;; providername=&#039;.Net Runtime&#039;; keywords=36028797018963968; ID=1023; level=2}<\/p>\n<p>That is all there is to using <b>Get-WinEvent<\/b> to look at event log keywords. Event Log Week will continue tomorrow when I will talk about more way cool stuff.<\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using a filter hash table to filter the event log with Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. The weather here in Charlotte, North Carolina has turned hot and humid. As a result, the Scripting Wife decided to migrate north for a while. Actually, she [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[97,98,3,45],"class_list":["post-1261","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-event-logs","tag-logs-and-monitoring","tag-scripting-guy","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, talks about using a filter hash table to filter the event log with Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. The weather here in Charlotte, North Carolina has turned hot and humid. As a result, the Scripting Wife decided to migrate north for a while. Actually, she [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=1261"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/1261\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=1261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=1261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=1261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}