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!



  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!

  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.

  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’

  4. Bryan Mendoza

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

  5. Balal Ahmad

    Great script , can anyone help me to make it
    import server names from csv ?

    • Manidipa Mazumdar

      $servers = Get-Content -Path “c:\computernames.csv”

      you should add this at the first line of your script. “c:\computernames.csv” should be the complete patch where you have seved your csv file

  6. Tom Servo

    is there a way to output to a txt file? I tried using

    Out-File c:\scripts\sys4.txt

    it creates the file but does not populate the file with the data, I’m really new to scripting and I’m sure I’m missing something pretty simple.


  7. vinay

    Tried to read from remote computer but facing below issue

    gwmi : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
    At D:\development\Time_zone.ps1:4 char:42
    + … tToDateTime((gwmi win32_operatingsystem -computername $server).LocalD …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Please let me know if we want to poll data from remote server, how


Leave a Reply

%d bloggers like this: