Friday, March 13, 2009

Finding Time

FindingTimes in Powershell (and cmd.exe).  I have put the script FindingTimes.ps1 in my repository.  I am returning various results.  This script demonstrates different methods of finding System Time and Uptime on Windows with cmd.exe or Powershell.  There is a discrepancy in the method results between .NET and GWMI. I do not know what is causing this, I suspect the hibernate process or uptime.exe heartbeat function (from MS Reskit) is causing the descrepancy.


PS D:\PS1> .\FindingTime_001.ps1
Finding Current and Boot Times from Powershell: A Medley of Methods
System Times:
Time now using Get-Date:
03/16/2009 19:41:35


DisplayHint : DateTime
DateTime    : Monday, March 16, 2009 7:41:35 PM
Date        : 3/16/2009 12:00:00 AM
Day         : 16
DayOfWeek   : Monday
DayOfYear   : 75
Hour        : 19
Kind        : Local
Millisecond : 343
Minute      : 41
Month       : 3
Second      : 35
Ticks       : 633728292953437500
TimeOfDay   : 19:41:35.3437500
Year        : 2009



Time From .NET:
.NET Date Time Now is 03/16/2009 19:41:35
.NET UTC Date Time Now is 03/17/2009 02:41:35
.NET Time is Date Hours Minutes Seconds MS : 16 19 41 35 359
.NET UTC Time is Date Hours Minutes Seconds MS : 17 2 41 35 359
.
Time from WMI Win32_OperatingSystem LocalDateTime:
03/16/2009 19:41:35
.
Time and Date from CMD.EXE:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\PS1>07:41 PM

D:\PS1>Mon 03/16/2009

D:\PS1>.
System UpTimes:
Uptime for cmd.exe
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

D:\PS1>Running cmd.exe

D:\PS1>Current TimeStamp is 03.16.2009_19.41.35.59
Statistics since 3/14/2009 9:45 AM
.
Uptime From Microsoft Resource Kit: 'D:\uptime.exe:'
\\RMFMEDIA has been up for: 2 day(s), 9 hour(s), 57 minute(s), 26 second(s)
.
Uptimes from the System Event 6009 Log Query and (get-date): Elapsed from Last Boot Times
Last boot Date/Time -- LBTs from Current Time in Days.Hours.Minutes.Seconds
03/14/2009 09:44:52 -- 2.9.56.44
03/04/2009 14:25:00 -- 12.5.16.36
02/20/2009 01:24:35 -- 24.18.17.1
02/19/2009 20:47:39 -- 24.22.53.57
02/18/2009 11:10:45 -- 26.8.30.51
02/16/2009 10:24:21 -- 28.9.17.15
02/16/2009 10:10:47 -- 28.9.30.49
02/03/2009 11:33:24 -- 41.8.8.12
01/15/2009 22:40:17 -- 59.21.1.19
01/09/2009 09:52:51 -- 66.9.48.45
01/07/2009 17:39:39 -- 68.2.1.57
01/05/2009 18:30:06 -- 70.1.11.30
01/05/2009 11:01:59 -- 70.8.39.37
12/24/2008 11:20:21 -- 82.8.21.15
.
Uptime from Get-WmiObject -class Win32_PerfFormattedData_PerfOS_System
Number of Days = 2.41489583333333
Number of Hours = 57.9575
Number of Minutes = 3477.45
Number of Seconds 208647
.
Uptme from GWMI Win32_OperatingSystem -Namespace root\CIMV2 LastBootUpTime and (get-date)
Last Boot Time: 03/16/2009 03:33:43 Current Time: 03/16/2009 19:41:36
Uptimes from Last Boot in Days.Hours.Minutes.Seconds = 0.16.7.52
.
Uptime from Get-WmiObject -class Win32_OperatingSystem LastBootUpTime and LocalDateTime
Uptime is 0.16.7.52
.
Uptime from D:\cygwin\bin\uptime.exe (procps version 3.2.6)
 19:41:36 up 16:07,  1 user,  load average: 0.00, 0.00, 0.00
.

No comments: