Check the Time on Remote Machines with PowerShell

I ran into an issue lately where the domain controller that hosts the PDC emulator FSMO role for the forest root domain became unavailable and the time for several machines in the domain was far enough off to start causing kerberos related security problems.

Here’s a simply Powershell script to query the time on remote machines via WMI. You could use Invoke-Command with Get-Date, but that takes too long compared to just using WMI. I chose to hard code the names I wanted to query directly into the script to eliminate having to keep up with a separate text file or trying to query Active Directory for the names since that may not be possible if the time is way off. This script is my solution to the “I have a problem and I want to eliminate the time on remote machines as a source of it”. I want the time and I want it now!

µ

5 Comments

  1. Joseph Garfield

    handy script…and get-date via powershell is MUCH more efficient than the old net time query I was running from cmd…thanks!

    Reply
  2. Ronn Husmann

    Not sure this script is working correctly. I ran it against remote servers and it reported back the times in CST. When I logged into some of them, clicked on Date/Time it actually showed EST.

    Reply
  3. spazzzen

    Just something you will want to add in, in case it can’t reach a “server”. the first line in the For loop should reset the time variable. i used: $time = ‘bad’

    Reply
  4. Bryan Mendoza

    where can i insert the convertto-csv command?, on that given script

    Reply

Leave a Reply

%d bloggers like this: