≡ Menu

PowerShell: Get time zone information remotely and export to CSV

This post tasks about fetching the time zone information from remote(as well as local) computers using PowerShell. We will be using two approaches to fetch this information. First one is using WMI classes and other is using the PowerShell built-in cmdlet.

First we will see how to fetch this information using WMI classes since it works with all versions of Windows. Time zone information in windows can be accessed via Win32_TimeZone WMI class. Apart from time zone, this class provide various other information as well. You can read more about this class at MSDN(https://msdn.microsoft.com/en-us/library/aa394498(v=vs.85).aspx). I will limit this article to time zone details only. We will be fetching this information from Caption property.

Fetch local time zone using WMI query

Get-WMIObject -Class Win32_TimeZone

Fetch remote time zone using WMI Query

Get-WMIObject -Class Win32_TimeZone -Computer Server01

You can write a simple script around the below command to fetch this information for list of computers. The output of this script will be exported to CSV for ease of viewing the results.


    [string[]]$ComputerName =  $env:COMPUTERNAME
$Col = @()
foreach($Computer in $ComputerName) {
    if(!(Test-Connection -ComputerName $Computer -count 1 -Quiet)) {
        Write-Host "$Computer : Not Reachable" -ForegroundColor Yellow

    try {
        $tzinfo = Get-WMIObject -Class Win32_TimeZone -ComputerName $Computer -ErrorAction Stop
        $Col += $tzinfo | select-Object PSComputerName, Caption, StandardName, DaylightName
        Write-Host "$computer : Successfully fetched the time zone info" -ForegroundColor Green
    } catch {
        Write-Host "$Computer : Failed to fetch the Time zone info" -ForegroundColor Yellow

$Col | export-csv -Path "c:\temp\timezoneinfo.csv" -NoTypeInformation

How to run the script?

#Read the servers list from text file to a variable
$servers = Get-Content c:\temp\servers.txt
#Run the script by passing servers list to it
.\Get-TimeZoneInfo.ps1 -ComputerName $servers


Second approach is to use built-in cmdlets. PowerShell comes with two cmdlets Get-TimeZone & Set-TimeZone starting PowerShell v5.1. We will be using Get-TimeZone to see how can retrieve the information.

Running this cmdlet without any arguments gives the time zone information of local computer. If you need to run this to fetch remotely there is no -ComputerName parameter available. However, you can PowerShell Remoting to execute it on remote host. Make sure that remote system also must be running PowerShell v5.1 or higher. Otherwise this will not work.

Fetch local time zone using cmdlet


Fetch Remote time zone using cmdlet

Invoke-Command -ComputerName SERVER01 -ScriptBlock { Get-TimeZone }

You can write a small script around the above command to run it against the multiple computers. The approach to do it is similar to what we have done for WMI based script above. You can give a try and post in comments section if you need help.

Hope this helps.

{ 0 comments… add one }

Leave a Comment