KQL query for fetching vm resources in a maintenance configurations

Garg,Srishti 20 Reputation points
2025-02-19T11:08:50.9066667+00:00

For configuring Azure update manager, I have created maintenance configuration for patching schedules where to evaluate vm resources for each configuration i was using tags to filter VMs on a scope of subscriptions i have (around 50) using Dynamic scope property in maintenance configuration. Hence doing configurations assignment to associate a schedule to a maintenance configuration.
I have a sample query with me. Can you help me with writing a correct query if this is feasible. I want to take out list VMs in each maintenance configurations.

resources
| where type == "microsoft.compute/virtualmachines"
| where subscriptionId == tolower(tostring(split(id, '/')[2]))  // Extract subscription ID from VM resource ID
| project vmName = name, vmId = id, resourceGroup, location, subscriptionId
| join kind=inner (
    maintenanceresources
    | where type == "microsoft.maintenance/configurationassignments"
    | where subscriptionId == tolower(tostring(split(id, '/')[2]))  // Extract subscription ID from maintenance configuration
    | project maintenanceConfigId = id, assignedSubscription = subscriptionId, configname=name
) on $left.subscriptionId == $right.assignedSubscription
| project vmName, vmId, resourceGroup, location, maintenanceConfigId, configname
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
8,434 questions
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,149 questions
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Deployment: The process of delivering, assembling, and maintaining a particular version of a software system at a site.
1,045 questions
Azure Update Manager
Azure Update Manager
An Azure service to centrally manages updates and compliance at scale.
353 questions
{count} votes

Accepted answer
  1. Nagarjuna Reddy Yanna 90 Reputation points Microsoft Vendor
    2025-02-24T01:20:54.65+00:00

    Hi Garg,Srishti,

    This query should now properly join the VM resources with their associated maintenance configurations based on their subscription IDs and scope.

    resources
    | where type == "microsoft.compute/virtualmachines"
    | extend subscriptionId = tolower(tostring(split(id, '/')[2]))  // Extract subscription ID once
    | extend tags = todynamic(tags)  // Parse tags as dynamic object
    | project vmName = name, vmId = id, resourceGroup, location, subscriptionId, tags
    | join kind=inner (
        resources
        | where type == "microsoft.maintenance/configurationassignments"
        | extend assignedSubscription = tolower(tostring(split(id, '/')[2]))  // Extract subscription ID once
        | mv-expand properties = todynamic(properties)  // Expand properties to access scopes
        | project maintenanceConfigId = id, assignedSubscription, configname = name, scope = tostring(properties.scope)
    ) on subscriptionId == assignedSubscription and id == scope
    | project vmName, vmId, resourceGroup, location, maintenanceConfigId, configname, tags
    
    
    

    Please refer blow Documentation for your refence

    https://learn.microsoft.com/en-us/azure/update-manager/scheduled-patching?tabs=schedule-updates-single-machine%2Cschedule-updates-scale-overview%2Cwindows-maintenance

    https://learn.microsoft.com/en-us/azure/update-manager/updates-maintenance-schedules

    https://learn.microsoft.com/en-us/azure/update-manager/prerequsite-for-schedule-patching?tabs=new-prereq-portal%2Cauto-portal

    https://learn.microsoft.com/en-us/azure/virtual-machines/maintenance-configurations

    https://learn.microsoft.com/en-us/azure/virtual-machines/resource-graph-samples?tabs=azure-cli

    If the information is helpful, please consider by clicking the "Upvote" on the post.

    If you have any further queries, please let us know in the comment.

    Thank you.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.