Working with PowerShell Cmdlets: Set-TimeZone
Welcome back to Wahmans PowerShell Blog! 😊
Today, we’ll take a deep dive into the Set-TimeZone cmdlet—a straightforward yet incredibly useful cmdlet that allows PowerShell users to programmatically change the time zone of their system.
What is Set-TimeZone?
As described in the official Microsoft documentation, Set-TimeZone “Sets the system time zone to a specified time zone.” This is especially useful for administrators managing systems across multiple geographic locations or when setting up new systems in a standard configuration.
Getting Started
First, it’s a good idea to see what time zones are available:
Get-TimeZone -ListAvailable
This command will return all valid time zones that you can use with Set-TimeZone.
Use Case Examples
Let’s look at some practical examples, from beginner to advanced usage:
🔰 Example 1: Set Your Time Zone to a Specific Region
Set-TimeZone -Name "Pacific Standard Time"
This example sets your system to Pacific Standard Time. Simple and useful when you need to quickly change time zones manually.
🔄 Example 2: Set Time Zone After OS Deployment
# In a setup script for new machines
Set-TimeZone -Name "UTC"
When you’re automating Windows workstation/server deployments, it’s standard practice to set time zone explicitly.
🔍 Example 3: Change Time Zone Based on Location Input
param (
[string]$Location = "Stockholm"
)
switch ($Location) {
"Stockholm" { Set-TimeZone -Name "W. Europe Standard Time" }
"New York" { Set-TimeZone -Name "Eastern Standard Time" }
"Tokyo" { Set-TimeZone -Name "Tokyo Standard Time" }
default { Write-Host "Unknown location" }
}
This script snippet allows dynamic time zone setting depending on geographical input. Useful in user profile provisioning or parameter-driven config scripts.
⚙️ Example 4: Remotely Setting Time Zone on Multiple Servers
$servers = @("Server01", "Server02", "Server03")
Invoke-Command -ComputerName $servers -ScriptBlock {
Set-TimeZone -Name "UTC"
}
Using Invoke-Command, this example applies the UTC time zone across a fleet of remote servers—a great use-case for system administrators maintaining global infrastructure.
Final Thoughts
Changing time zones via PowerShell using Set-TimeZone is easy, elegant, and highly automatable. Whether you’re managing a single system or orchestrating custom time zone settings across an enterprise, this cmdlet is a great addition to your toolbox.
Happy scripting, and I will see you in the next post! 👋
Leave a Reply