Hi,
I think this is the query you are looking for. Example is to list all VMs that have BGInfo and do not have IaaSAntimalware extensions.
resources
| where type == 'microsoft.compute/virtualmachines'
| extend
JoinID = toupper(id),
OSName = tostring(properties.osProfile.computerName),
OSType = tostring(properties.storageProfile.osDisk.osType),
VMSize = tostring(properties.hardwareProfile.vmSize),
departmentTag = tostring(tags['Department'])
| join kind=inner(
resources
| where type == 'microsoft.compute/virtualmachines/extensions'
| where name =~ 'BGInfo' and name !~ 'IaaSAntimalware'
| extend
VMId = toupper(substring(id, 0, indexof(id, '/extensions'))),
ExtensionName = name
) on $left.JoinID == $right.VMId
| summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize, name, resourceGroup, departmentTag
| order by tolower(OSName) asc
Updated query:
resources
| where type == 'microsoft.compute/virtualmachines'
| extend
JoinID = toupper(id),
OSName = tostring(properties.osProfile.computerName),
OSType = tostring(properties.storageProfile.osDisk.osType),
VMSize = tostring(properties.hardwareProfile.vmSize),
departmentTag = tostring(tags['Department'])
| join kind=inner(
resources
| where type == 'microsoft.compute/virtualmachines/extensions'
| where name =~ 'BGInfo' or name =~ 'IaaSAntimalware'
| extend
VMId = toupper(substring(id, 0, indexof(id, '/extensions'))),
ExtensionName = name
) on $left.JoinID == $right.VMId
| summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize, name, resourceGroup, departmentTag
| where Extensions notcontains 'IaaSAntimalware'
| order by tolower(OSName) asc
Third and last update:
resources
| where type == 'microsoft.compute/virtualmachines'
| extend
JoinID = toupper(id),
OSName = tostring(properties.osProfile.computerName),
OSType = tostring(properties.storageProfile.osDisk.osType),
VMSize = tostring(properties.hardwareProfile.vmSize),
departmentTag = tostring(tags['Department'])
| join kind=inner(
resources
| where type == 'microsoft.compute/virtualmachines/extensions'
| extend
VMId = toupper(substring(id, 0, indexof(id, '/extensions'))),
ExtensionName = name
) on $left.JoinID == $right.VMId
| summarize Extensions = make_list(ExtensionName) by id, OSName, OSType, VMSize, name, resourceGroup, departmentTag
| where Extensions notcontains 'IaaSAntimalware'
| where Extensions contains 'BGInfo'
| order by tolower(OSName) asc
Please "Accept the answer" if the information helped you. This will help us and others in the community as well.