Hi guys, I hope you all are having a nice week so far!
We have an Autopilot provisioning package that has been working great for a long time now on win 10, but some of the configs and policies did not work well on Win 11 so we modified some of them, others we replaced with scripts. Among the things that do not work as expected is the automatic Time Zone setting. We push a script that sets TZ to be automatic, and it does impact as expected (during OOBE first login). Problem is, the TZ is NOT set properly until you restart the device or force the service to refresh.
Since the client tasked us to provide a ready to use device, making the end user restart their computer is not an option. After manually restarting tzautoupdate service with positive results (the TZ corrected to the right one without having to restart the computer), we then crafted a simple script that would do the same during provisioning...but it does not work.
We added logging to make sure the script was actually running. The log even indicates the service was successfully stopped and started again, but the Time Zone does not change to the right one.
Here's the script, very simple and rudimentary but it is just what we intend to do with automation:
# Define log file path
$LogFilePath = "C:\Intune\logs\tzautoupdate_log.txt"
# Ensure log directory exists
if (-Not (Test-Path "C:\Intune\logs"))
{
New-Item -ItemType Directory -Path "C:\Intune\logs"
}
# Function to log messages
function Log-Message {
param ([string]$Message)
Add-Content -Path $LogFilePath -Value "$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss')) - $Message"
}
# Log current time zone
$currentTimeZone = (Get-TimeZone).Id
Log-Message "Current Time Zone: $currentTimeZone"
# Stop the tzautoupdate service
try
{
Stop-Service -Name tzautoupdate -Force
Log-Message "tzautoupdate service stopped successfully."
Start-Sleep -Seconds 10
}
catch
{
Log-Message "Failed to stop tzautoupdate service: $_"
}
# Start the tzautoupdate service
try
{
Start-Service -Name tzautoupdate
Log-Message "tzautoupdate service started successfully."
}
catch
{
Log-Message "Failed to start tzautoupdate service: $_"
}
# Log time zone after restart
$updatedTimeZone = (Get-TimeZone).Id
Log-Message "Updated Time Zone: $updatedTimeZone"
Is there a better option? Or a simpler one to achieve the same?
Thank you very much in advance for your answers and suggestions!