Problems setting a timezone using Set-TimeZone

Introduction

This is just a quick post to give some detail about a problem I dealt with, because when searching for it I got no direct hits to my specific problem, at least not for “Singapore Standard Time”.

We prompt our Windows Autopilot users to confirm the Timezone, Regional  format and Country after first login and that’s been working great so far, until a user in Singapore tried it, and the timezone was not set correctly even though it was correctly listed.

The list of timezone’s in the dropdown is created using the following

Get-TimeZone -listavailable | Export-CSV TimeZones.txt

 

Running that will indeed list the “Singapore Standard Time” timezone as shown here.

I debugged the script and found the following was happening. The script uses Powershell to set the timezone using the Set-TimeZone cmdlet, for example:

Set-TimeZone -name "Singapore Standard Time"

Running that in Powershell should set the time zone correctly, however it doesn’t !

The error is:

Set-TimeZone : The time zone name 'Singapore Standard Time' was not found on the local computer.

Which was odd !

Resolution

After looking through the registry I found this key.

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\Singapore Standard Time

And if you look at the value listed for Std, it’s Malay Peninsula Standard Time.

So I was attempting to set the timezone based on what windows returned as the Id, instead I should be setting it based on the StandardName.

a closer look at get-timezone reveals that info is actually present..

So armed with that knowledge I did the following fix…

and using the above does correctly set the Singapore time zone. Job done !

This entry was posted in PowerShell, timezone. Bookmark the permalink.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.