{"id":13351,"date":"2011-07-11T00:01:00","date_gmt":"2011-07-11T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/07\/11\/use-date-types-to-filter-event-trace-logs-in-powershell\/"},"modified":"2011-07-11T00:01:00","modified_gmt":"2011-07-11T00:01:00","slug":"use-date-types-to-filter-event-trace-logs-in-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/use-date-types-to-filter-event-trace-logs-in-powershell\/","title":{"rendered":"Use Date Types to Filter Event Trace Logs in PowerShell"},"content":{"rendered":"<p><strong>Summary<\/strong>: Learn how to use date types to filter event trace logs in Windows PowerShell.<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hey, Scripting Guy! I am wondering, oh great scripting master: can I use Windows PowerShell to parse an ETW log file?<\/p>\n<p>&mdash;JM<\/p>\n<p>&nbsp;<\/p>\n<p><img decoding=\"async\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\" \/>Hello JM,<\/p>\n<p>Microsoft Scripting Guy Ed Wilson here. It is &ldquo;oh dark thirty&rdquo; in the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Piedmont_(United_States)\">Piedmont region of the United States<\/a>. For some reason, I woke up early. It is Thursday as I write this article, and the Scripting Wife and I were up late last night listening to the <a href=\"http:\/\/powerscripting.wordpress.com\/\">PowerScripting Podcast<\/a>. I thought Spencer Brown did a great job as the guest, and as usual, Hal Rottenberg was in top form as he played the suave and debonair talk show host. Jonathan Walz was grooving in the background&mdash;audiophile extraordinaire. The Scripting Wife loves the chat room conversation because it gives her a chance to hang out with her friends from all over the world. Anyway, because I was up late, and then again up early, I decided it would make for a great excuse to have a <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2009\/03\/04\/how-do-i-migrate-my-vbscript-wmi-queries-to-windows-powershell.aspx\">coffee day<\/a>. My last coffee day occurred back in January when I was talking about <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/01\/12\/schedule-powershell-scripts-that-require-input-values.aspx\">scheduling Windows PowerShell scripts that require input values<\/a>.<\/p>\n<p>Anyway, JM, the &ldquo;standard answer&rdquo; is that Windows PowerShell can do anything. The other day on Twitter, someone asked if Windows PowerShell could be made to mow the grass. I believe it could be (here is a cool article about <a href=\"https:\/\/channel9.msdn.com\/coding4fun\/articles\/Part-2-Controlling-a-Microbric-Viper-Robot-with-an-IR-Serial-Port-using-NET-and-PowerShell\">using Windows PowerShell to control robots<\/a>). Now all you need is a robot lawn mower.<\/p>\n<p>In <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2011\/07\/09\/use-powershell-to-troubleshoot-windows.aspx\">Saturday&rsquo;s Weekend Scripter article<\/a>, I talked about working with Event Tracing for Windows (ETW) logs. I discussed how to enable and disable the logs, and how to use the <b>Get-WinEvent<\/b> cmdlet to find and to read the trace.<\/p>\n<p>The first thing to do is to obtain the name of the log and to store it in a variable. I do this because it makes working interactively from the Windows PowerShell line easier to do. The actual log name I want to work with today is <i>Microsoft-Windows-WMI-Activity\/Trace<\/i>. I can find the log name from one of the trace entries when I look in Event Viewer. Such an entry appears in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0407.HSG-7-11-11-01.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of finding log name from trace entry in Event Viewer\" alt=\"Image of finding log name from trace entry in Event Viewer\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/0407.HSG-7-11-11-01.png\" \/><\/a><\/p>\n<p>After I have the log name stored in a variable, I can use the <b>Get-WinEvent<\/b> cmdlet to retrieve the <b>message<\/b> property (or other properties as appropriate). The following two commands store the <i>Microsoft-Windows-WMI-Activity\/Trace <\/i>log name in a variable, and return the <b>message<\/b> property from each of the entries in the WMI Activity trace ETW log:<\/p>\n<p style=\"padding-left: 30px\">$wmiLog = (Get-WinEvent -ListLog *wmi*trace -force).logname<\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent -LogName $wmilog -Oldest | select message<\/p>\n<p>The two commands and associated output are shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5226.HSG-7-11-11-02.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of two commands and associated output\" alt=\"Image of two commands and associated output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/5226.HSG-7-11-11-02.png\" \/><\/a><\/p>\n<p>In the previous figure, the output of the <b>message<\/b> property appears truncated. At times, a truncated output provides enough information to allow for quick identification of a particular problem. In the case of the above output, there is not enough detailed information to allow for much exploration. The solution is to expand the <b>message<\/b> property. To expand the <b>message<\/b> property, use the <b>expandproperty<\/b><i> <\/i>property from the <b>Select-Object<\/b> cmdlet. Here is the syntax of this command:<\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent -LogName $wmilog -Oldest | select -ExpandProperty message&nbsp;<\/p>\n<p>The command and associated output are shown in the following figure.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3808.HSG-7-11-11-03.png\"><img decoding=\"async\" style=\"border: 0px\" title=\"Image of command and associated output\" alt=\"Image of command and associated output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/3808.HSG-7-11-11-03.png\" \/><\/a><\/p>\n<p>In attempting to work with individual event entries, it would be logical to use the date timestamp in a filter. I therefore take the time, cast it to a <b>system.datetime<\/b> object, and use it with a <b>Where-Object<\/b> filter. Unfortunately, no records are returned from the query. The two commands are shown here:<\/p>\n<p style=\"padding-left: 30px\">$date = [datetime]&#8221;7\/6\/2011 6:03:51 PM&#8221;<\/p>\n<p style=\"padding-left: 30px\">Get-WinEvent -LogName $wmilog -Oldest | where-object { $_.timecreated -eq $date }<\/p>\n<p>If I change the operator from <b>equals<\/b> to <b>greater than<\/b>, the command produces output. The revised command and associated output are shown here (the <b>?<\/b> character is an alias for <b>Where-Object<\/b>).<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-WinEvent -LogName $wmilog -Oldest | ? { $_.timecreated -gt $date }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">TimeCreated<\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; <span style=\"text-decoration: underline\">ProviderName<\/span>&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;<span style=\"text-decoration: underline\">Id Message<\/span><\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2 ProviderInfo for&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:04:01 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:04:42 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:04:42 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>The reason the equality operator does not return any objects is because the <b>timecreated<\/b> property is an instance of a <b>system.datetime<\/b> object, and as such the property is more complex than a simple string. The following command explores the <b>timecreated<\/b> property. Both the command and associated output are shown here (the command is broken at the pipeline character for the sake of readability; in reality, it is normally typed on a single line):<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-WinEvent -LogName $wmilog -Oldest -MaxEvents 1 |<\/p>\n<p style=\"padding-left: 30px\">Get-Member -Name timecreated<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;&nbsp; TypeName: System.Diagnostics.Eventing.Reader.EventLogRecord<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">Name<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">MemberType<\/span>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Definition<\/span><\/p>\n<p style=\"padding-left: 30px\">TimeCreated Property&nbsp;&nbsp; System.Nullable`1[[System.DateTime, mscorlib, Version&#8230;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>I can use the <b>maxevents<\/b> property to help retrieve a single record for exploration. In the following command, I store the <b>eventlogrecord<\/b> object in a variable named <b>$record<\/b><i>.<\/i> I then display the <b>timecreated<\/b> property. The commands and output follow:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $record = Get-WinEvent -LogName $wmilog -Oldest -MaxEvents 1<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $record.TimeCreated<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Wednesday, July 06, 2011 6:03:51 PM<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>To get a better idea of what is involved in the <b>datetime<\/b> object, I send the results from the <b>TimeCreated<\/b> property across the pipeline to the <b>Format-List<\/b> cmdlet. I use the <i>force<\/i> parameter to ensure that any hidden properties display. The command and associated output are shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $record.TimeCreated | Format-List -Force<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7\/6\/2011 12:00:00 AM<\/p>\n<p style=\"padding-left: 30px\">Day&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 6<\/p>\n<p style=\"padding-left: 30px\">DayOfWeek&nbsp;&nbsp; : Wednesday<\/p>\n<p style=\"padding-left: 30px\">DayOfYear&nbsp;&nbsp; : 187<\/p>\n<p style=\"padding-left: 30px\">Hour&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 18<\/p>\n<p style=\"padding-left: 30px\">Kind&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : Local<\/p>\n<p style=\"padding-left: 30px\">Millisecond : 776<\/p>\n<p style=\"padding-left: 30px\">Minute&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 3<\/p>\n<p style=\"padding-left: 30px\">Month&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 7<\/p>\n<p style=\"padding-left: 30px\">Second&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 51<\/p>\n<p style=\"padding-left: 30px\">Ticks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 634455722317760648<\/p>\n<p style=\"padding-left: 30px\">TimeOfDay&nbsp;&nbsp; : 18:03:51.7760648<\/p>\n<p style=\"padding-left: 30px\">Year&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 2011<\/p>\n<p style=\"padding-left: 30px\">DateTime&nbsp;&nbsp;&nbsp; : Wednesday, July 06, 2011 6:03:51 PM<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>If I hone in on the <b>timeofday<\/b> property from the <b>timecreated<\/b><i> <\/i>property, I see that another object is returned. The command and associated output are shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $record.TimeCreated.TimeOfDay<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\">Days&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0<\/p>\n<p style=\"padding-left: 30px\">Hours&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 18<\/p>\n<p style=\"padding-left: 30px\">Minutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 3<\/p>\n<p style=\"padding-left: 30px\">Seconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 51<\/p>\n<p style=\"padding-left: 30px\">Milliseconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 776<\/p>\n<p style=\"padding-left: 30px\">Ticks&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 650317760648<\/p>\n<p style=\"padding-left: 30px\">TotalDays&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 0.752682593342593<\/p>\n<p style=\"padding-left: 30px\">TotalHours&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 18.0643822402222<\/p>\n<p style=\"padding-left: 30px\">TotalMinutes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 1083.86293441333<\/p>\n<p style=\"padding-left: 30px\">TotalSeconds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : 65031.7760648<\/p>\n<p style=\"padding-left: 30px\">TotalMilliseconds : 65031776.0648<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>When I am only interested in the type of object contained in a property, I use the <b>gettype<\/b> method directly. The use of the <b>gettype<\/b> method and associated output are shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; ($record.TimeCreated.TimeOfDay).gettype()<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">IsPublic<\/span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">IsSerial<\/span>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">Name<\/span>&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">BaseType<\/span><\/p>\n<p style=\"padding-left: 30px\">True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; True&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TimeSpan&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.ValueType<\/p>\n<p>&nbsp;<\/p>\n<p>It is possible to use the ticks to filter records. There are a couple of ticks available for this use. The first is a tick associated with the <b>timespan<\/b> object. <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.timespan.ticks.aspx\">This tick<\/a> represents 100 nanoseconds since midnight. The tick is the smallest unit of time. In the code that follows, the <b>ticks<\/b> property from the <b>timespan<\/b> object contained in the <b>timeofday<\/b> property is displayed. Next, I store the tick in the <b>$ticks<\/b><i> <\/i>variable, and use it to display event log entries that occur at the same time of day. The commands and associated output are shown here.<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $record.TimeCreated.TimeOfDay.Ticks<\/p>\n<p style=\"padding-left: 30px\">650317760648<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $ticks = $record.TimeCreated.TimeOfDay.Ticks<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; Get-WinEvent -LogName $wmilog -Oldest |<\/p>\n<p style=\"padding-left: 30px\">? { $_.timecreated.timeofday.ticks -eq $ticks }<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p style=\"padding-left: 30px\"><span style=\"text-decoration: underline\">TimeCreated<\/span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"text-decoration: underline\">ProviderName<\/span>&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; <span style=\"text-decoration: underline\">Id Message<\/span><\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1 GroupOperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">7\/6\/2011 6:03:51 PM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft-Window&#8230;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 Stop OperationId&#8230;<\/p>\n<p style=\"padding-left: 30px\">&nbsp;<\/p>\n<p>The other <b>ticks<\/b><i> <\/i>property that is available is the one directly on the <b>system.datetime<\/b> object stored in the <b>timecreated<\/b> property. <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/system.datetime.ticks.aspx\">This <b>ticks<\/b> property<\/a> represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight, January 1, 0001. The value of <b>ticks<\/b> from the <b>datetime<\/b> object is shown here:<\/p>\n<p style=\"padding-left: 30px\">PS C:\\&gt; $record.TimeCreated.Ticks<\/p>\n<p style=\"padding-left: 30px\">634455722317760648<\/p>\n<p>&nbsp;<\/p>\n<p>JM, that is all there is to filtering ETW logs in the <b>Get-WinEvent<\/b> cmdlet using time stamps. Troubleshooting Windows Week will continue tomorrow when I will talk about searching the message results.&nbsp;<\/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\">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><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Learn how to use date types to filter event trace logs in Windows PowerShell. &nbsp; Hey, Scripting Guy! I am wondering, oh great scripting master: can I use Windows PowerShell to parse an ETW log file? &mdash;JM &nbsp; Hello JM, Microsoft Scripting Guy Ed Wilson here. It is &ldquo;oh dark thirty&rdquo; in the Piedmont [&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,31,60,3,4,134,61,45,6],"class_list":["post-13351","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-event-logs","tag-logs-and-monitoring","tag-operating-system","tag-performance","tag-scripting-guy","tag-scripting-techniques","tag-troubleshooting","tag-weekend-scripter","tag-windows-powershell","tag-wmi"],"acf":[],"blog_post_summary":"<p>Summary: Learn how to use date types to filter event trace logs in Windows PowerShell. &nbsp; Hey, Scripting Guy! I am wondering, oh great scripting master: can I use Windows PowerShell to parse an ETW log file? &mdash;JM &nbsp; Hello JM, Microsoft Scripting Guy Ed Wilson here. It is &ldquo;oh dark thirty&rdquo; in the Piedmont [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13351","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=13351"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/13351\/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=13351"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=13351"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=13351"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}