Query LogAnalytics for Azure Virtual Machine Tag?




 I have a process that adds some tags to VMs in Azure.  I would love to query log analytics for these tags. 


 Here is an example of the tags:



I found this query to parse VMInsights tags but am not sure where to go to look up these tags.



extend Tags = parse_json(Tags)

where Tags.["AutomanagedPC"has "true"


Any tips would be greatly appreciated :)


2 Replies



InsightMetrics tags are not the ones you are looking for. But why are you using Log Analytics? This type of queries should be targeted at Azure Resource Graph instead.


Read the following article: https://docs.microsoft.com/en-us/azure/governance/resource-graph/first-query-portal 


And use this ARG query:


| where type =~ 'Microsoft.Compute/virtualMachines'
| where tags.AutomanagedPC == 'true'


You can also use ARG via Az PowerShell or CLI: https://docs.microsoft.com/en-us/azure/governance/resource-graph/overview#running-your-first-query 

The unfortunate part is we have a workbook from the Workspace for MDE status, list any server that is having MDE issues, it would be great to have the TAGS from the server listed.