Get-TimeZone in PowerShell

The Get-TimeZone cmdlet in PowerShell retrieves the current time zone of a computer. It can also list all available time zones, which is helpful if you’re planning to make changes to the system’s time zone settings.

In this post I’m sharing two examples of how to check the local time zone with PowerShell:

> Get Time Zone using PowerShell
> Script to Output Available Time Zones to a CSV File

Get the Time Zone using PowerShell

Running Get-TimeZone in PowerShell will return the currently set timezone of the local Windows Computer.

# get timezone powershell
Get-TimeZone
Get timezone PowerShell
The above shows we are on GMT Standard Time, UTC+00:00.

Script to Output Available Time Zones to a CSV File

The following PowerShell script outputs all available time zones to a CSV file in a specified directory:

# output available timezones to a local directory
$path = "c:\temp\"
$output_file_name = "timezones_available.csv"
$full_output_path = $path + $output_file_name

If(!(test-path $path))
{
    New-Item -ItemType Directory -Force -Path $path
}
Get-TimeZone -ListAvailable | Export-Csv -Path $full_output_path -NoTypeInformation -Force

I saved this script to my c:\temp folder and ran it:

timezone output powershell

The CSV will contain all time zones available:

poiwershell output to excel

This isn’t really a regular or task that you’d be doing often. I’m more just noting a different way of saving this info.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Certificates & Encryption (3) Change Data Capture (CDC) (2) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Deleting Data (1) Error Messages (5) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Admin (2) Logging & Monitoring (1) Measuring Databases (10) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (1) SQL Server Agent (5) SQL Server Database Files (1) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (15) SQL Server Network Connectivity (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance (6) SQL Server Permissions (2) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) Windows Admin (21) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)