PowerShell for Windows Admins

Mar 4 2010   2:35PM GMT

What’s the time



Posted by: Richard Siddaway
Tags:
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

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: