PowerShell for Windows Admins

Mar 4 2010   2:35PM GMT

What’s the time



Posted by: Richard Siddaway
Automation, WMI

 

I was answering a question about time synchronisation and it got me wondering about check the time on multiple machines.

001
002
003
004
005
006
007
008
009
010
011
012
$computer = "." 
Get-WmiObject -Class Win32_LocalTime -ComputerName $computer | foreach {
    "Local Time"
    Get-Date -Day $_.Day -Month $_.Month -Year $_.Year `
      -Hour $_.Hour -Minute $_.Minute -Second $_.Second
}

Get-WmiObject -Class Win32_UTCTime -ComputerName $computer | foreach {
    "UTC Time"
    Get-Date -Day $_.Day -Month $_.Month -Year $_.Year `
      -Hour $_.Hour -Minute $_.Minute -Second $_.Second
}

 

We can use a simple bit of WMI to check both the Local time and UTC time if we span multiple time zones.  if you need to check many machines put the code in a function and pass the computer names from a  csv file

Technorati Tags:

Comment on this Post

Leave a comment: