Forum Discussion

nareshunik86's avatar
nareshunik86
Copper Contributor
Oct 30, 2020

Get date,time and timezone

I am looking for a script to get date,time, timezone from multiple remote servers (3000) using power shell.
Please help me to get script.

3 Replies

  •  

    Hi nareshunik86,

     

    Could you try that PowerShell script?

     

    $ComputerNames = Get-Content "C:\Servers.txt"
    
    foreach($ComputerName in $ComputerNames) 
            { 
     
            $TimeZone=Get-WmiObject -Class win32_timezone -ComputerName $ComputerName 
            $LocalTime = Get-WmiObject -Class win32_localtime -ComputerName $ComputerName 
            $Output =@{'ComputerName' = $LocalTime.__SERVER; 
                        'Time Zone' = $TimeZone.Caption; 
                        'Current Time' = (Get-Date -Day $LocalTime.Day -Month $LocalTime.Month); 
                       } 
            $Object = New-Object -TypeName PSObject -Property $Output 
            Write-Output $Object 
            }

     

    Servers.txt is a text file which includes your servers' names.

     

     

  • farismalaeb's avatar
    farismalaeb
    Iron Contributor

    nareshunik86 

    Hi

    Try to make a look on WMI

    this is the powershell query to get the date and time from remote computer

    Get-WmiObject -ComputerName REMOTE_COMPUTER -Query 'select * from Win32_CurrentTime where __CLASS ="Win32_LocalTime"'

    For the timezone, you can use TZUTIL 

Resources