Get date,time and timezone

%3CLINGO-SUB%20id%3D%22lingo-sub-1838727%22%20slang%3D%22en-US%22%3EGet%20date%2Ctime%20and%20timezone%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1838727%22%20slang%3D%22en-US%22%3EI%20am%20looking%20for%20a%20script%20to%20get%20date%2Ctime%2C%20timezone%20from%20multiple%20remote%20servers%20(3000)%20using%20power%20shell.%3CBR%20%2F%3EPlease%20help%20me%20to%20get%20script.%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1838727%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EWindows%20PowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1840936%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20date%2Ctime%20and%20timezone%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1840936%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F852238%22%20target%3D%22_blank%22%3E%40nareshunik86%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%3C%2FP%3E%3CP%3ETry%20to%20make%20a%20look%20on%20WMI%3C%2FP%3E%3CP%3Ethis%20is%20the%20powershell%20query%20to%20get%20the%20date%20and%20time%20from%20remote%20computer%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EGet-WmiObject%20-ComputerName%20REMOTE_COMPUTER%20-Query%20'select%20*%20from%20Win32_CurrentTime%20where%20__CLASS%20%3D%22Win32_LocalTime%22'%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3EFor%20the%20timezone%2C%20you%20can%20use%26nbsp%3B%3CSPAN%3ETZUTIL%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1864814%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20date%2Ctime%20and%20timezone%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1864814%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F852238%22%20target%3D%22_blank%22%3E%40nareshunik86%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20try%20that%20PowerShell%20script%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3E%24ComputerNames%20%3D%20Get-Content%20%22C%3A%5CServers.txt%22%0A%0Aforeach(%24ComputerName%20in%20%24ComputerNames)%20%0A%20%20%20%20%20%20%20%20%7B%20%0A%20%0A%20%20%20%20%20%20%20%20%24TimeZone%3DGet-WmiObject%20-Class%20win32_timezone%20-ComputerName%20%24ComputerName%20%0A%20%20%20%20%20%20%20%20%24LocalTime%20%3D%20Get-WmiObject%20-Class%20win32_localtime%20-ComputerName%20%24ComputerName%20%0A%20%20%20%20%20%20%20%20%24Output%20%3D%40%7B'ComputerName'%20%3D%20%24LocalTime.__SERVER%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Time%20Zone'%20%3D%20%24TimeZone.Caption%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Current%20Time'%20%3D%20(Get-Date%20-Day%20%24LocalTime.Day%20-Month%20%24LocalTime.Month)%3B%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%0A%20%20%20%20%20%20%20%20%24Object%20%3D%20New-Object%20-TypeName%20PSObject%20-Property%20%24Output%20%0A%20%20%20%20%20%20%20%20Write-Output%20%24Object%20%0A%20%20%20%20%20%20%20%20%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EServers.txt%20is%20a%20text%20file%20which%20includes%20your%20servers'%20names.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Visitor
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.
2 Replies

@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 

 

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.