{"id":2671,"date":"2011-04-14T11:17:00","date_gmt":"2011-04-14T11:17:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2011\/04\/14\/using-get-winevent-filterxml-to-process-windows-events\/"},"modified":"2024-02-28T12:10:06","modified_gmt":"2024-02-28T20:10:06","slug":"using-get-winevent-filterxml-to-process-windows-events","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/using-get-winevent-filterxml-to-process-windows-events\/","title":{"rendered":"Using Get-WinEvent \u2013FilterXml to process Windows Events"},"content":{"rendered":"<p class=\"MsoNormal\"><b><span style=\"font-size: small;\"><span style=\"color: #3366ff;\">Introduction<\/span><\/span><\/b><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">Windows Events can be extremely useful\u00a0for debugging. Administrators often use events to diagnose problems in complex systems. However, Event Viewer is time-consuming and difficult to automate. Luckily, there is a simple way to fully automate the process. <\/span><\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: small;\"><span style=\"color: #3366ff;\">The FilterXml Parameter<\/span><\/span><\/b><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: Calibri; font-size: small;\">The FilterXml parameter allows you\u00a0use a simple XML document to filter events quickly. You can use the &#8220;Create Custom View&#8221; and &#8220;Filter Current Log&#8221; features in Event Viewer to create a valid XML query. The exact query schema can be found here: <\/span><a href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkId=143685\"><span style=\"font-family: Calibri; color: #0000ff; font-size: small;\">http:\/\/go.microsoft.com\/fwlink\/?LinkId=143685<\/span><\/a><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">.<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><b><span style=\"font-size: small;\"><span style=\"color: #3366ff;\">An Example<\/span><\/span><\/b><\/p>\n<p class=\"MsoNormal\">\n<p class=\"MsoNormal\">\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: helvetica;\"><span style=\"font-size: small;\"><span style=\"font-family: tahoma,arial,helvetica,sans-serif;\"><span style=\"font-size: x-small;\"><span style=\"font-family: Calibri; font-size: small;\">In Event Viewer, select a log, and then click\u00a0&#8220;Filter Current Log&#8221;&#8230;<\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><a href=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20441\" src=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog.png\" alt=\"Image 3806 FilterCurrentLog\" width=\"557\" height=\"557\" srcset=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog.png 557w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog-300x300.png 300w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog-150x150.png 150w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog-24x24.png 24w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog-48x48.png 48w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/3806.FilterCurrentLog-96x96.png 96w\" sizes=\"(max-width: 557px) 100vw, 557px\" \/><\/a><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri; font-size: small;\">Select the items to filter and then click the XML tab.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><a href=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-20442\" src=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL.png\" alt=\"Image 4426 FilterMXL\" width=\"557\" height=\"557\" srcset=\"https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL.png 557w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL-300x300.png 300w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL-150x150.png 150w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL-24x24.png 24w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL-48x48.png 48w, https:\/\/devblogs.microsoft.com\/powershell\/wp-content\/uploads\/sites\/30\/2011\/04\/4426.FilterMXL-96x96.png 96w\" sizes=\"(max-width: 557px) 100vw, 557px\" \/><\/a><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri; font-size: small;\">Now you can use the XML query in Windows PowerShell.<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">PS C:\\Windows\\system32&gt; $filterXml = &#8216;&lt;QueryList&gt;<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">\u00a0 &lt;Query Id=&#8221;0&#8243; Path=&#8221;Windows PowerShell&#8221;&gt;<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">\u00a0\u00a0\u00a0 &lt;Select Path=&#8221;Windows PowerShell&#8221;&gt;*[System[(Level=4 or Level=0)]]&lt;\/Select&gt;<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">\u00a0 &lt;\/Query&gt;<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-family: 'Courier New';\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">&lt;\/QueryList&gt;\u2019<\/span><\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">PS C:\\Windows\\system32&gt; Get-WinEvent \u2013FilterXml $filterXml<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">TimeCreated\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ProviderName\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Id Message<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">&#8212;&#8212;&#8212;&#8211;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212;&#8212;&#8212;&#8212;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &#8212; &#8212;&#8212;-<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:01 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0600 Provider &#8220;WSMan&#8221; is Starte&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:00 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 600 Provider &#8220;Variable&#8221; is Sta&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:00 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0600 Provider &#8220;Registry&#8221; is Sta&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:00 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 600 Provider &#8220;Function&#8221; is Sta&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:00 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0600 Provider &#8220;FileSystem&#8221; is S&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:00 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 600 Provider &#8220;Environment&#8221; is &#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:48:00 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 600 Provider &#8220;Alias&#8221; is Starte&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: courier new,courier;\"><span style=\"font-size: x-small;\">4\/14\/2011 10:47:58 AM\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 PowerShell\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 400 Engine state is changed fr&#8230;<\/span><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">This query retrieves all Windows PowerShell events. You can then pipe the results to downstream cmdlets for further processing.<\/span><\/span><\/p>\n<p class=\"MsoNormal\">\n<p class=\"MsoNormal\"><span style=\"font-size: small;\"><span style=\"font-family: Calibri;\">James Wei\nSDE\nMSFT<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Windows Events can be extremely useful\u00a0for debugging. Administrators often use events to diagnose problems in complex systems. However, Event Viewer is time-consuming and difficult to automate. Luckily, there is a simple way to fully automate the process. The FilterXml Parameter The FilterXml parameter allows you\u00a0use a simple XML document to filter events quickly. You [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2671","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>Introduction Windows Events can be extremely useful\u00a0for debugging. Administrators often use events to diagnose problems in complex systems. However, Event Viewer is time-consuming and difficult to automate. Luckily, there is a simple way to fully automate the process. The FilterXml Parameter The FilterXml parameter allows you\u00a0use a simple XML document to filter events quickly. You [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2671","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=2671"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/2671\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=2671"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=2671"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=2671"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}