'Is there a way to List all the VM's from the Application Security Group

As we know we can group the Vm's into a single App Security Group and use them as a Single Entity for the NSG rules.

I'm searching a way to find what are all the VM's thats associated to my security group.

From the azure CLI its showing the properties of App Security Group, but not the Association of VM's it does.

Is there a way to get/list all the VM's for a given Application Security Group ?



Solution 1:[1]

You have to look at this from the NIC. If you do a az network nic list you can see the ASG's assigned to a NIC. You can look at this answer on how to list out the nic's associated with a VM.

azure cli list nic attached to VM

Solution 2:[2]

Ken provided the exact path to the solution. All I need to do is to to find the relevant queries(jmespath) in Azure CLI . I used the below query to get the desired solution for my use-case

az network nic list --query "[].[ipConfigurations[].applicationSecurityGroups[? contains(id,``<replace-your-asg-name>``)],virtualMachine]"

Ofcourse the above query needs some work as it will still show all VM list . May be it will give some lead to others to enhance it more precise for their needs.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ken W MSFT
Solution 2