KQL query for fetching vm resources in a maintenance configurations

Garg,Srishti 40 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.
9,036 questions
Microsoft Security | Intune | Configuration Manager | Deployment
Azure Update Manager
Azure Update Manager
An Azure service to centrally manages updates and compliance at scale.
376 questions
Microsoft Security | Microsoft Graph
{count} votes

Accepted answer
  1. Anonymous
    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.