How to get Virtual machine date time in Log analytics

Deepaklal-FT 66 Reputation points
2022-06-01T12:29:49.077+00:00

Hi,

Can someone help me to get Virtual machine date time in Log analytics or via writing a KQL query?

This is to compare the time in two virtual machines in same region.

Pseudo code

  1. Check the date time in VM1
  2. Check the date time in VM2
  3. Print the time difference
  4. If Time is different Alert/Display error message in log analytics
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,968 questions
Azure ISV (Independent Software Vendors) and Startups
Azure ISV (Independent Software Vendors) and Startups
Azure: A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.ISV (Independent Software Vendors) and Startups: A Microsoft program that helps customers adopt Microsoft Cloud solutions and drive user adoption.
91 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. ShaikMaheer-MSFT 38,321 Reputation points Microsoft Employee
    2022-06-03T06:02:46.25+00:00

    Hi @Deepaklal-FT ,

    Thank you for posting query in Microsoft Q&A Platform.

    KQL query which runs on Log analytics cannot directly get local VMs date and time.

    There is something called now() function in KQL that can get you current date time in UTC. To this function by passing offset value we can get desired timezone date time information. Please check below screenshot where I am getting IST from UTC.
    208122-image.png

    But if above doesn't help and You are very particular about getting local system date time only then We need to think of having some local code which runs on your VMs to get systems local date time info and store that info to log analytics custom tables. Once data stored in custom tables you can query them as per need.

    Please here your local code can be using PowerShell or SDK or any other way of programming and scripting which you comfort.

    Hope this helps. Please let us know if any further queries.

    ----------

    Please consider hitting Accept Answer. Accepted answers help community as well.