Thursday 15 September 2011

datetime - Powershell date comparison not returning expected results -


Not sure I'm doing something wrong but I hope that the result is not being found.

To return a UTC date / time value, then I can request both local and remote machines to have the following functions

  Function Get-UTCTime {Ultimate ([String] $ computername = $ env .: computername) $ UTC = get- WmiObject win32_utctime -ComputerName $ computername return $ sysdt = ([string] $ utc.month + "/" + [string] $ utc.day + "/ [+ [String] $ utc.year +" "+ [string] $ utc.hour +": "+ [string] $ utc.minute +": "+ [string] $ utc.second)} [datetime ] $ Lsysdt = Get- UTCTime "". Type Host "Local:" $ lsysdt [datetime] $ rsysdt = Get- UTCTime $ Computer Write-Off "Remote:" $ rsysdt.addminutes (6) $ tester1 = $ lsysdt - $ rsysdt $ tester2 = New-TimeSpan -Start $ Lsysdt end $ rsysdt type host "tester1" $ tester1 type host "tester2" $ tester2   

My results are as follows

  Local: 6 / 21/2013 6:06:43 PM Remote: 6/21/2013 6:12:45 PM Examiner 1 -00: 00: 02 Examiner 2 00:00:02   

You You can see that I have 6 minutes and 2 second difference in time, but the resultant value is only Identifies Ekand.

I have expanded all properties on tester1 variable and still do not see that it contains minutes.

  Ticks: -20000000 Days: 0 hours: 0 milliseconds: 0 minutes: 0 seconds: -2 TotalDays: -2.31481481481481E-05 TotalHours: -00555555555555556 TotalMilliseconds: -2000 TotalMinutes: -. 0333333333333333 TotalSeconds: -2   

What is the simple low concept I am missing with Datetime Comparison?

  function get-UTCTime {absolute ([string] $ computer) $ computer = $ Env: COMPUTERNAME $ UTC = get- WmiObject win32_utctime -ComputerName $ computer return $ sysdt = ([string] $ utc.month + "/" + [string] $ utc.day + "/" + [string] $ utc .year + "" + [string] $ utc.hour + ":" + [string] $ utc.minute + ":" + [string] $ UTC second]} [that time] $ lsysdt = Get-UTCTime ". "Host Type" Local: "$ lsysdt [datetime] $ rsysdt = Get- UTCTime $ Computer Write-Off" Remote: "$ rsysdt.addminutes (6) $ newRsysdt = $ rsysdt.addminutes (6) $ t Ester1 = $ lsysdt - $ newRsysdt $ tester2 = New-TimeSpan -Start $ lsysdt End $ newRsysdt Type Host "Tester 1" $ tester1 Type Host "Tester 2" $ tester2    

No comments:

Post a Comment