Compare Local Date and Time to a Remote Computer
This is a rather interesting problem. I was doing a comparison between an audit table and a trace for SQL Server, which was proving to be dificult as I soon realized there was latency as well as the system date’s had an offset. So I turned to my good old friend, Powershell. Powershell has a very nice interface for coding against WMI, which I fully leveraged in this code snippet.
#Server name here. $ServerName = <Server Name Here> #Retreive the localtime of the server. $remoteDate = Get-WmiObject -ComputerName $ServerName -Class win32_operatingsystem -Property LocalDateTime #Converting a WMI time to a standard datetime format. $remoteDate = [System.Management.ManagementDateTimeConverter]::ToDateTime($remoteDate.LocalDateTime) $localDate = Get-Date #Displaying the difference. $remoteDate - $localDate
Image may be NSFW.
Clik here to view.

Clik here to view.
