I'm writing a PowerShell Runbook that will schedule the execution of a Runbook using the New-AzAutomationSchedule call. However, no matter how I enter the time, it still adjusts it to UTC.
Here's specifically what's happening...
New-AzAutomation -AutomationAccountName $AccountName -ResourceGroupName $RGName -Name $Name -DayInterval 1 -StartTime "0800"
Schedules my job for 8AM UTC.
New-AzAutomation -AutomationAccountName $AccountName -ResourceGroupName $RGName -Name $Name -DayInterval 1 -StartTime "0800" -TimeZone "America/Chicago"
Schedules my job for 3AM Central Time.
What I want is it to be 8AM Central Time and I don't want to have to manually calculate whether it's daylight savings or not, ideally. Using CoPilot, ChatGPT 4o, and Claude 3 have given me some really convoluted code that I would hope is not necessary.
I've also tried adding the "Z" to the StartTime, but I get the same results.
I am using the PowerShell 5.1 runtime because I need to use the SqlServer module and that isn't working properly for PowerShell 7.1 or 7.2 runtimes (that's an active issue I'm working with Microsoft support on - looks like others have this same problem).
I'm sure I'm either doing something really stupid, or I'm running into a quick of Azure Automation. Any help point me in the right direction would be appreciated. Thank you!
Cannot get New-AzAutomationSchedule to set the correct timezone
The issue is that the New-AzAutomationSchedule
cmdlet does not take into account the local timezone
when scheduling the runbook execution. It uses UTC
time as the reference point for scheduling.
You can use the below script to manually convert the desired local time to UTC before passing it to the New-AzAutomationSchedule
cmdlet.
Command:
$localTime = Get-Date "04:00 PM" -Format "HH:mm:ss"
$utcTime = $localTime.AddHours([System.TimeZone]::CurrentTimeZone.GetUtcOffset($localTime).Hours)
New-AzAutomationSchedule -ResourceGroupName "<resourcegrp>" -AutomationAccountName "automation account name" -Name "MySchedule" -DayInterval 1 -StartTime $utcTime -TimeZone "America/Chicago"
Output:
StartTime : 25-06-2024 10:30:00 -05:00
ExpiryTime : 31-12-9999 12:29:59 -06:00
IsEnabled : True
NextRun : 25-06-2024 10:30:00 -05:00
Interval : 1
Frequency : Day
MonthlyScheduleOptions :
WeeklyScheduleOptions :
TimeZone : America/Chicago
ResourceGroupName : xxxxxx
AutomationAccountName : venkatautomation326
Name : MySchedule
CreationTime : 25-06-2024 15:21:24 +05:30
LastModifiedTime : 25-06-2024 15:21:24 +05:30
Description :
Portal:
Reference: New-AzAutomationSchedule: Incorrect Timezone Adjustment in PowerShell Runbook (trycatchdebug.net) by Try Catch Debug.