«

»

Oct 31

Powershell Code: Set a Server’s Time Zone Based on the Time Zone Setting on another Server

Windows synchronizes and stores time internally in UTC (aka GMT). Configuring a time zone on the server enables the server to display time local to the location of the server. This simplifies identifying when the server may be rebooted (8pm is probably acceptable, though 9am probably is not). Furthermore, scheduled tasks run at the time based on the Time Zone offset configuration.

Time Zone configuration on computers can be tricky. Some would argue that this is probably the only time a site-based Group Policy makes sense (update Time Zone script in a GPO). However, in most situations, it isn’t that difficult to set the server’s time zone when it is installed.

Here’s a neat script that configures a local server’s time zone based on the time zone setting on another server. This saves manual entry errors and the time it takes to configure it through the GUI.

########################
# Configure Time Zone #
########################
Write-Verbose "This component will configure the Time Zone based on the Time Zone of another server `r "
Write-Verbose "Prompt for Time Zone Configuration `r "

$TZServer = [Microsoft.VisualBasic.Interaction]::InputBox("Please enter the servername which has the correct time zone information you wish to use",`
 "Get Time Zone from Server","")
$TimeZone = Get-WMIObject -class Win32_TimeZone -ComputerName $TZServer
$TZDescription = $TimeZone.Description
$TZDaylightTime = $TimeZone.DaylightName
$TZStandardTime = $TimeZone.StandardName
write-output "Timezone is now set to $TZDescription `r " 

write-output "Configuring the Time Zone [$TZStandardTime] on $Computer... `r "
$TZResult = TZUTIL /s $TZStandardTime
Share

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>