Automatically configure the time zone (during Autopilot enrollment)

New Windows devices usually come out of the box with the time zone configured to Pacific Time. Great for people who live in that time zone, but I assume most of the people live in another time zone, like me and all the users of my employer. Thus, when we started our investigation into moving our Windows device management to Microsoft Intune, we also investigated how to automatically configure the time zone on our newly enrolled Windows devices.

As written in a very old blog post, we can configure the time zone with an Intune configuration profile. But a downside of this is that if the user changes the time zone the time zone will be converted back because of the policy re-applying. So, this might be an option when managing a shared desktop, or kiosk device, but not for laptops like we use a lot.

We wanted to have a solution that we could deploy during Autopilot enrollment so that the time zone is configured before the user is signed in. If possible, we wanted to set the time zone to the time zone where the user is when the enrollment is performed. We didn’t want to set a time zone based on which country owns the device, because of people who can be traveling all around the world.

After searching the web, I found a great solution mentioned in the comments of a community blog. It described a script that checks the location of the device and matches the location with a list of time zones found via an online service of Bing. We have been using this solution for quite some time for our cloud-managed devices.
Recently I wanted to share it with somebody else, but I couldn’t find it anymore! After further searching, I found the original comment from Koen van den Broeck.

But I think it deserves more visibility because, in my opinion, it’s a good solution. Therefore, I’m sharing it (with his permission) here in a blog post. But again, all credits are to Koen for his solution!

The solution in short

The solution is a PowerShell script that is (in our case) wrapped as WIN32 app, that runs during Autopilot enrollment.

The first part of the script where the magic happens first queries the service for the IP address data of the device’s internet connection.
With the retrieved location, the script checks at another service, Bing Maps, for the matching time zone.

When the time zone is retrieved, it configures the time zone on the Windows device.

The script can be found on GitHub.


As described the script calls two online services. can be used without a license, but please check the website for the current API Access limitations.
Note; if the device is connected to a network from which traffic is routed via a proxy, for example, this might show another location as the actual location of the device.

Using the API of the Bing Maps service requires us to create a Bing API key, thus requiring an account on the platform. Depending on the usage of the key, you should be fine with a Basic (Dev/ test) key that is free of usage, or you need to purchase a license. Also, check this yourself on

The script in more details

It’s not a very long script, but let’s divide it into a few parts and look at what it does for us.
In the functions region, we define a CleanUpAndExit function, which is also used for Intune detection when wrapped as a win32 package.

In the variables section, of course, the variables are set, from which you most likely want to change the company name. And you should add the Bing API key, otherwise, the script won’t do its job.

Next, we start the transcript, which writes some logging to the IntuneManagementExtension\Logs folder. By writing the logs to that folder, it is available when collecting Device diagnostics with Intune.

The last part is where Koen his magic happens.
It performs an Invoke-RestMethod call to to retrieve the location of the device.
This location is then used to convert the location to a time zone using the Bing service.
Once we have retrieved the time zone, it is set in the last part of the script.

And that’s all for this automatic time zone configuration solution.
The time zone is configured before the user is first signed in when the script is deployed during Autopilot enrollment. the user can still change it when traveling around the world.

As written, we can deploy the script wrapped as WIN32 app with Intune, during the Windows Autopilot enrollment. But you can also just deploy it as script using Intune or change it to your needs and use it as a Remediation in Intune. Although I can imagine that the script then runs so often that the free versions of the used services are not sufficient.

In case you’re deploying the script as WIN32 app, this is how the detection rule looks like.

Happy testing!


  1. This is great, where ware you using for detection logic if you wrap it in Win32? I’m struggling with that part.

  2. Hi,

    I get this error related with TLS … I’ve tried to enforce it with no success. Do you know how to fix it ?

    Invoke-WebRequest – The underlying connection was closed: An unexpected error occurred on a send.

    Thank you

    • Sorry I was trying to say that I’ve tried to enforce TLS … this way

      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls -bor [Net.SecurityProtocolType]::Tls11 -bor [Net.SecurityProtocolType]::Tls12

      But no success

      Thanks in advance

  3. Bing Maps unfortunately has no future, right after we implemented it:

    • Customers using Bing Maps for Enterprise Basic or Free license will no longer be able to use Bing Maps for Enterprise services beyond June 30, 2025.

    (a) Basic / Free Licenses customers who would like to continue using enterprise maps from Microsoft are encouraged to move to Azure Maps before June 30, 2025.

    (b) Existing Basic / Free Licenses customers who would like to continue using Bing Maps for Enterprise until the service end date of June 30, 2028, can upgrade to a paid Enterprise License by contacting before June 30, 2025.

Leave a Reply

Your email address will not be published.