{"id":15371,"date":"2011-03-09T00:01:00","date_gmt":"2011-03-09T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/03\/09\/discover-how-to-filter-remote-event-log-entries-in-windows-vista\/"},"modified":"2011-03-09T00:01:00","modified_gmt":"2011-03-09T00:01:00","slug":"discover-how-to-filter-remote-event-log-entries-in-windows-vista","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/discover-how-to-filter-remote-event-log-entries-in-windows-vista\/","title":{"rendered":"Discover How to Filter Remote Event Log Entries in Windows Vista"},"content":{"rendered":"<p><b>Summary<\/b>: Learn how to use Windows PowerShell to filter remote event log entries in a Windows Vista computer.<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Question\" border=\"0\" title=\"Hey, Scripting Guy! Question\" \/>&nbsp; Hey, Scripting Guy! I thought your article yesterday was really great. It was interesting how a rather simple change could provide such a big gain in performance. The problem is that it does not appear to work on my Windows XP laptop. That laptop is really old, but it is running Windows PowerShell 2.0. So, I tried it on my Windows Vista desktop, and the command still did not work. I am beginning to wonder if you were having an off day yesterday. It might be understandable with all the stuff you were into last week. I just thought I would give you the benefit of the doubt. <\/p>\n<p>&mdash;JJ<\/p>\n<p><img decoding=\"async\" height=\"34\" width=\"34\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" align=\"left\" alt=\"Hey, Scripting Guy! Answer\" border=\"0\" title=\"Hey, Scripting Guy! Answer\" \/> Hello JJ, <\/p>\n<p>Microsoft Scripting Guy, Ed Wilson here. You are right, last week was an incredible Windows PowerShell week, and I got to meet a huge number of awesome Microsoft MVPs, as well as a great group of Microsoft engineers. It was a long week, and (seemingly) an even longer flight, but I learned a lot, and I had a tremendous amount of fun. I appreciate your willingness to cut me some slack, but in this particular instance, such slack cutting is not warranted. You happen to be suffering from goofy cmdlet syndrome&mdash;luckily it is curable by upgrading to Windows 7 or Windows Server 2008 R2. <\/p>\n<p>The <b>Get-WinEvent<\/b> cmdlet, although present on a Windows PowerShell 2.0 installation for Windows XP, does not work. In a way, this makes sense because of the changes in the Event Logs that took place in Windows Vista. The error message generated in Windows XP makes it clear that the <b>Get-WinEvent<\/b> cmdlet requires at least Windows Vista to run. The error message is shown here.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5415.HSG-3-9-11-01_3AE4AD65.jpg\"><img decoding=\"async\" height=\"296\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1033.HSG-3-9-11-01_thumb_77B92F37.jpg\" alt=\"Image of error message\" border=\"0\" title=\"Image of error message\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>So far, so good. This sort of makes sense. But what about your problem with Windows Vista (incidentally, the same problem exists on Windows Server 2008)? In Windows Vista, the <b>Get-WinEvent<\/b> cmdlet is unable to use the <i>FilterHashTable <\/i>parameter; the other functionalities of the <b>Get-WinEvent<\/b> cmdlet work properly.<i> <\/i>This does not mean that all filters do not work, only the <i>FilterHashTable <\/i>filter. This is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4338.HSG-3-9-11-02_14DED742.jpg\"><img decoding=\"async\" height=\"374\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4353.HSG-3-9-11-02_thumb_32DCE536.jpg\" alt=\"Image of error message\" border=\"0\" title=\"Image of error message\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>In Windows XP, you will need to use the <b>Get-EventLog<\/b> cmdlet. To maximize performance of the query use the <i>source, InstanceID, After, Before, <\/i>and <i>EntryType <\/i>parameters to filter information before returning it to the Windows PowerShell console. <\/p>\n<p>Luckily, you can use an XML filter by supplying XML to the <i>FilterXML <\/i>parameter of the <b>Get-WinEvent<\/b> cmdlet. Windows Vista and Windows Server 2008 accept the an XML filter, as do Windows 7 and Windows Server 2008 R2. Because most IT pros do not relish the idea of hand crafting XML files, you can copy the XML code from the XML tab of the Filter Current Log tab from the Event Viewer. To produce the XML, right-click the appropriate event log in Event Viewer, and select the Filter Current Log task. On the Filter pane, choose the applicable parameters including the Event source, time constraint, and Event level. The filter pane is shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6825.HSG-3-9-11-03_696A907A.jpg\"><img decoding=\"async\" height=\"607\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/6332.HSG-3-9-11-03_thumb_5FC22244.jpg\" alt=\"Image of filter pane\" border=\"0\" title=\"Image of filter pane\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>When the filter is created, the XML tab of the Filter Current Log pane shows the XML that is used to create the current filter. By highlighting the XML, and pressing Ctrl+C to copy it to the clipboard, the XML portion of the <i>FilterXML<\/i> parameter is generated. The XML tab is shown in the following graphic.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4375.HSG-3-9-11-04_7D53FD43.jpg\"><img decoding=\"async\" height=\"604\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/1638.HSG-3-9-11-04_thumb_0FBC4DF9.jpg\" alt=\"Image of XML tab\" border=\"0\" title=\"Image of XML tab\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>I like to place the XML into a non-expanding here-string. As seen here, this command will run against a remote computer. <\/p>\n<blockquote>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">$query = @&#8217;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;QueryList&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;Query Id=&#8221;0&#8243; Path=&#8221;Application&#8221;&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;Select Path=&#8221;Application&#8221;&gt;*[System[Provider[@Name=&#8217;Microsoft-Windows-WMI&#8217;] and TimeCreated[timediff(@SystemTime) &amp;lt;= 604800000]]]&lt;\/Select&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;\/Query&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;\/QueryList&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&#8216;@<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">Get-WinEvent -FilterXml $query -ComputerName vista<\/span><\/p>\n<\/blockquote>\n<p>The command and the associated output appear in the following graphic.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8507.HSG-3-9-11-05_0D331C3B.jpg\"><img decoding=\"async\" height=\"434\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4705.HSG-3-9-11-05_thumb_43C0C77F.jpg\" alt=\"Image of command output\" border=\"0\" title=\"Image of command output\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>The <b>Get-WinEvent<\/b> cmdlet does not accept an array of computer names for the <i>computername <\/i>parameter, but it is easy to use the <b>Foreach<\/b> statement to work through an array of computer names. This is illustrated in the DemoXMLFilterQueryArrayComputers.ps1 script shown here.<\/p>\n<p>DemoXMLFilterQueryArrayComputers.ps1<\/p>\n<blockquote>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">$query = @&#8217;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;QueryList&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;Query Id=&#8221;0&#8243; Path=&#8221;Application&#8221;&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;Select Path=&#8221;Application&#8221;&gt;*[System[Provider[@Name=&#8217;Microsoft-Windows-WMI&#8217;] and TimeCreated[timediff(@SystemTime) &amp;lt;= 604800000]]]&lt;\/Select&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;\/Query&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&lt;\/QueryList&gt;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">&#8216;@<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">$aryComputers = &#8220;dc1&#8243;,&#8221;hyperv-box&#8221;, &#8220;Vista&#8221;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">foreach($computer in $aryComputers)<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">{ &#8220;Computer $computer`r`n&#8221;<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">Get-WinEvent -FilterXml $query -ComputerName $computer<\/span><\/p>\n<p><span style=\"font-family: Lucida Sans Typewriter;font-size: x-small\">}<\/span><\/p>\n<\/blockquote>\n<p>When the script runs, the output that is shown in the following graphic appears in the Windows PowerShell ISE output pane.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/8422.HSG-3-9-11-06_32F91CD1.jpg\"><img decoding=\"async\" height=\"434\" width=\"604\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/7838.HSG-3-9-11-06_thumb_4C80A9FE.jpg\" alt=\"Image of command output\" border=\"0\" title=\"Image of command output\" style=\"border-bottom: 0px;border-left: 0px;padding-left: 0px;padding-right: 0px;border-top: 0px;border-right: 0px;padding-top: 0px\" \/><\/a><\/p>\n<p>JJ, that is all there is to using the <b>Get-Winevent<\/b> cmdlet on Windows Vista and Windows Server 2008. In addition, I hope I have explained why the cmdlet does not work on Windows XP. I hope you will check back tomorrow for more Windows PowerShell tips and tricks. <\/p>\n<p>I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> and <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a>, or post your questions on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><b>Ed Wilson, Microsoft Scripting Guy<\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use Windows PowerShell to filter remote event log entries in a Windows Vista computer. &nbsp; Hey, Scripting Guy! I thought your article yesterday was really great. It was interesting how a rather simple change could provide such a big gain in performance. The problem is that it does not appear to [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[97,51,98,3,4,134,45],"class_list":["post-15371","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-event-logs","tag-getting-started","tag-logs-and-monitoring","tag-scripting-guy","tag-scripting-techniques","tag-troubleshooting","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use Windows PowerShell to filter remote event log entries in a Windows Vista computer. &nbsp; Hey, Scripting Guy! I thought your article yesterday was really great. It was interesting how a rather simple change could provide such a big gain in performance. The problem is that it does not appear to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/15371","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\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=15371"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/15371\/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=15371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=15371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=15371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}