How to Set Timezone Using PowerShell

Rohan Timalsina Feb 17, 2024
  1. Use Get-TimeZone to Get the Time Zone in PowerShell
  2. Use Set-TimeZone to Set the Time Zone in PowerShell
  3. Use tzutil to Set the Time Zone in PowerShell
  4. Conclusion
How to Set Timezone Using PowerShell

Managing time zones is crucial for accurate time representation and synchronization in PowerShell. Understanding how to retrieve and set time zones ensures that scripts and system configurations operate effectively.

PowerShell offers several methods for managing time zones, including Get-TimeZone and Set-TimeZone cmdlets, as well as the tzutil command-line utility. Each method provides unique capabilities and advantages, empowering users to tailor time zone configurations to their specific needs.

In this article, we explore these methods in detail, providing insights into their usage and functionality.

Use Get-TimeZone to Get the Time Zone in PowerShell

The Get-TimeZone cmdlet in PowerShell serves as a fundamental tool for retrieving the current time zone configuration on a system. When executed without parameters, it simply displays the current time zone in use.

Get-TimeZone

Output:

set timezone using powershell - output 1

The -ListAvailable parameter provides a comprehensive list of all available time zones on the system. This list is essential for selecting a valid time zone when setting the system’s time zone.

Get-TimeZone -ListAvailable

Output:

set timezone using powershell - output 2

Use Set-TimeZone to Set the Time Zone in PowerShell

PowerShell provides a straightforward method for setting the timezone using the Set-TimeZone cmdlet. This cmdlet allows users to specify the timezone ID, facilitating accurate time representation and synchronization.

Setting the time zone by Id involves providing the corresponding time zone identifier as an argument to the -Id parameter.

Set-TimeZone -Id "Pacific Standard Time" -PassThru

In this example, we utilize the Set-TimeZone cmdlet to modify the system’s timezone. We provide the -Id parameter along with the desired timezone ID, such as "Pacific Standard Time", directing PowerShell to adjust the system’s timezone accordingly.

Additionally, we can opt to use the -PassThru parameter, which allows us to view the timezone information post-change.

Output:

set timezone using powershell - output 3

Setting the time zone by Name is also feasible, requiring the -Name parameter to match the target time zone’s StandardName or DaylightName properties. The Id and Name of the time zone do not always match.

Set-TimeZone -Name "Pacific Standard Time" -PassThru

Output:

set timezone using powershell - output 4

Use tzutil to Set the Time Zone in PowerShell

For alternative time zone management in PowerShell, the tzutil command-line utility provides another approach for setting the timezone of a system. tzutil is particularly useful when you need to change the timezone through command-line interfaces or in scripts.

Syntax:

tzutil /s "TimezoneId"
  • /l: Lists all available time zones on the system.
  • /g: Retrieves the currently set time zone ID.
  • /s "TimezoneId": Sets the system’s time zone to the specified time zone ID.
  • /?: Displays the usage information at the terminal.

To set the system’s time zone using tzutil, execute the command with the /s parameter followed by the desired time zone identifier enclosed in double quotes.

tzutil /s "Pacific Standard Time"
tzutil /g

In our workflow, we utilize the tzutil command to manage the system’s timezone settings. By specifying the /s parameter followed by the desired timezone ID enclosed in double quotes, like "Pacific Standard Time", we direct tzutil to modify the system’s timezone accordingly.

By leveraging the /s parameter, users effectively direct tzutil to adjust the system’s time zone according to the specified identifier. This straightforward approach streamlines the process of updating time zone configurations as needed.

Output:

set timezone using powershell - output 5

Conclusion

PowerShell offers versatile tools for managing time zones, catering to various scripting and administrative requirements. Whether querying current time zone information, setting time zones programmatically, or managing time zones through command-line interfaces, PowerShell provides robust solutions.

By leveraging the Get-TimeZone and Set-TimeZone cmdlets, as well as the tzutil utility, users can efficiently retrieve, modify, and synchronize time zone settings across Windows systems. Understanding these methods empowers users to navigate time zone management challenges effectively, ensuring accurate time representation and synchronization in PowerShell environments.

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website

Related Article - PowerShell Timezone