Welcome to the Microsoft Q&A Platform. Thank you for reaching out & I hope you are doing well.
I am not sure why you would like to query NSGs and Subnets together, as this would mean "subnets.name" and "subnets.properties.addressPrefix" would be empty (null) for the NSGs
However, the below query should do the trick
Resources
| where type == 'microsoft.network/virtualnetworks' or type == 'microsoft.network/networksecuritygroups'
| extend subnets = properties.subnets
| mv-expand subnets
| project name, subnets.name, subnets.properties.addressPrefix, location, resourceGroup, ['type'], subscriptionId
| sort by ['type'], name asc
| project-away ['type']
P.S :
- I am sorting based on Resource Type so that NSGs appear together and the Subnets appear together.
- The NSGs and Subnets themselves are sorted in Ascending order withing their group
Please let us know if we can be of any further assistance here.
Thanks,
Kapil
Please Accept an answer if correct.
Original posters help the community find answers faster by identifying the correct answer.