Most of the time, we don’t care that much about the time when running Azure Automation. However, in some specific cases, we need the tasks to check local time to perform some Azure Automation actions. One of my customers wants to start and shutdown VMs based on a schedule, and I don’t want to do the match with Universal Time every time. Also, UTC does not help with the customer time zone changes and changes in the code would be required.
One approach that worked for me was converting the current Get-Date cmdlet to UTC. You may be wondering, Azure is already UTC, but if you want to go back and forth with the same code between on-prem and Azure, having that conversion at the beginning won’t hurt you.
After getting the time in a variable, the second step is to define the time zone that you want to use (in our case EST), and last but not least, convert the time using the initial variable and the time zone defined.
$tempDate =(Get-Date).ToUniversalTime() $tzEST = [System.TimeZoneInfo]::FindSystemTimeZoneById("Eastern Standard Time") $CurrentTime = [System.TimeZoneInfo]::ConvertTimeFromUtc($tempDate, $tzEST)
If you want to use that information throughout your script, make sure to use the -Date and use the variable that contains the time in your time zone.
Get-Date -Date $CurrentTime -UFormat %u (Get-Date -Date $CurrentTime).Hour
We can create a simple PowerShell Runbook and add the code that we have seen so far to get an idea of how it would work.
As we can see, the UTC was 8:08p.m.. and EST was 3:08 p.m. after converting the date information. It is useful for scripts that are sensitive to the local time of the customer instead of Azure Automation.
Featured image: Pixabay
By establishing these 11 appropriate controls beforehand, your organization will be better positioned to withstand and survive a DDoS attack.
If your shop is considering using App-V as an application virtualization solution, read this article first and weigh the pros…
As companies and individuals harden their defenses against ransomware, hackers are creating new and more virulent ransomware threats.
AWS is the public cloud market leader. But Google Cloud is catching up. One thing is sure: In the AWS-Google…
What is going to be significant in the world of web design over the course of 2020? Let’s take a…
Microsoft Intune is a great and powerful tool. Here’s how to use it for mobile device management to keep track…