scloud by Florian Salzmann
ende

Automatically Set the Time Zone in Intune Autopilot

When I first saw Peter Klapwijk’s solution, I was impressed. It used an IP lookup via a URL and an Azure Maps Account to detect the correct time zone during Autopilot enrollment.
I have used it primarly in Europe, with great success.

This week, I implemented it for a US-based customer. That’s when I noticed a challenge:
For countries with multiple time zones, Azure Maps returns several results, making it unclear which one to apply.
I started looking for an alternative and discovered that the IPInfo API provides a single, precise time zone value using their legacy free API.

The best part?
No Azure Maps account is needed.
This makes the setup easier, faster, and without extra services.

The legacy free API from IPInfo could be deprecated in the future, but at the time of writing, there is no end-of-life date.

How it works

The script queries the IPInfo API, retrieves the IANA time zone, and converts it into the Windows time zone format using the official Microsoft mapping XML.
It then applies the time zone directly on the device.

This approach is perfect for Autopilot scenarios, where devices are enrolled in Intune without user interaction.

Get the script

Download my ready-to-use script from GitHub:

Set-TimeZoneByIPAddress.ps1

It’s a single PowerShell file with no dependencies apart from the Windows OS itself.

How it works

The script:

  1. Calls http://ipinfo.io/json to get the device’s IANA time zone
  2. Downloads the Microsoft windowsZones.xml mapping
  3. Converts the IANA time zone into the Windows time zone format
  4. Applies the time zone using Set-TimeZone

Example output during execution:

.\Set-TimeZoneByIPAddress.ps1
Fetching IANA time zone from ipinfo.io...
Detected IANA Time Zone: Europe/Zurich
Downloading custom XML mapping...
Searching for matching mapping...
Mapped to Windows Time Zone: W. Europe Standard Time
Setting Windows time zone using Set-TimeZone...
Successfully set Windows Time Zone: W. Europe Standard Time

This approach is perfect for Autopilot scenarios, where devices are enrolled in Intune without user interaction.

How to deploy via Intune

Option 1: Deploy as a platform script

  1. Go to DevicesScripts in the Intune Admin Center
  2. Create a new Windows PowerShell script
  3. Upload the Set-TimeZoneByIPAddress.ps1 file
  4. Set Run this script using the logged-on credentials to No
  5. Set Run script in 64-bit PowerShell to Yes
  6. Assign the script to your Autopilot device group

This method is fast to set up and works well if you just need to run the script once during enrollment.

Option 2: Deploy as a Win32 app

For more flexibility and better logging, you can package the script as a Win32 app.

First add this at the bottom to the first script (we will use it as the detectionlater)

$Path = "HKLM:\SOFTWARE\scloud\Set-TimeZoneByIPAddress"
$Key = "Version" 
$KeyFormat = "dword"
$Value = "1"

if(!(Test-Path $Path)){New-Item -Path $Path -Force}
if(!$Key){Set-Item -Path $Path -Value $Value
}else{Set-ItemProperty -Path $Path -Name $Key -Value $Value -Type $KeyFormat}
  1. Create a folder with your .ps1 file and an install command
  2. Use the Microsoft Win32 Content Prep Tool to convert it to .intunewin
  3. In the Intune Admin Center, create a new Windows app (Win32)
  4. Upload your .intunewin package
  5. Use this install command: %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -executionpolicy bypass -command .\Set-TimeZoneByIPAddress.ps1
  6. And this uninstall command: reg delete "HKLM\SOFTWARE\scloud\Set-TimeZoneByIPAddress" /f
  7. Detection rule:
    • HKEY_LOCAL_MACHINE\SOFTWARE\scloud\Set-TimeZoneByIPAddress
    • Version
    • Equals 1
  8. Assign it to your Autopilot device group

This method gives you greater control over reruns, detection logic and versioning, and makes it mandatory in Autopilot (v1). However, this only applies to Autopilot and not to Autopilot Device Preparation (Autopilot v2). With Device Preparation, you have greater control over script execution and can choose to run this platform script before the user logs in.

Why this is better for multi-time-zone countries

Unlike Azure Maps, which might return multiple possible zones for a country, IPInfo provides a single, accurate match for the device’s location.
This is especially valuable in the US, Canada, Australia, and other large countries with multiple zones.

Conclusion

With this new script, setting the correct time zone in Intune Autopilot becomes much simpler.
No Azure Maps account, no ambiguity for multi-zone countries, and no extra services to maintain.

You can implement it in minutes and ensure your devices always start with the correct time.