Log generation time using Win32_NTLogEvent query in WMI timegenerated similar to "20130820162350.350000+480", this time format is very special, is the DMTF time format string, Comparisons with other time types in PowerShell require conversion and the DMTF string to a datetime type.
There are two scenarios for conversion: 1) using. NET The System.Management.ManagementDateTimeConverter class in 2.0 is located in the System.management.dll Dynamic link library, which needs to be loaded first, with the following code: [void][ Reflection.assembly]::loadfile ("C:\windows\microsoft.net\framework\v2.0.50727\system.management.dll") gwmi Win32 _ntlogevent-filter "logfile= ' Application ' and sourcename= ' DB2 '"-property timegenerated,message-com $ip |select Message,@{name= "LogTime"; Expression={[system.management.managementdatetimeconverter]::todatetime ($_. timegenerated)}}|sort Logtime-desc 2) Use the extension method of the Event object Converttodatetimegwmi-q "select TimeGenerated from Win32_NTLogEvent WHERE logfile= ' application ' and sourcename= ' DB2 ' "|%{$_. Converttodatetime ($_. timegenerated)}
Time format Conversion