Azure Resource Graph - Not Equals with Wildcard

121 Views Asked by At

Trying to query resources in Azure resource graph, but I cannot seem to get the wildcard working as intended. For example, AKS spins up a bunch of disk PVCs with the name "pvc-[some_guid]", which I am trying to eliminate from my query return. Any idea on how to accomplish this? The below query is the example I am using, I am attempting to return all names except the names with the "pvc-[some_guid] in them.

 resources 
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState) 
| where  diskState == 'Unattached'
| where name != "pvc-*"
| join kind=inner (
    resourcecontainers
    | where type == 'microsoft.resources/subscriptions'
    | project subscriptionId, subscriptionName = name)
    on subscriptionId 
| project name, diskState, managedBy, subscriptionName, resourceGroup, location

Thought I could use the wildcard with the where name != "pvc-*", but that does not appear to be the case.

1

There are 1 best solutions below

1
Aswin On

The != operator does not support wildcards. It will only match exact string values. To exclude disk names that start with "pvc-", you can use the startswith() function instead.

 resources 
| where type has "microsoft.compute/disks"
| extend diskState = tostring(properties.diskState) 
| where  diskState == 'Unattached'
| where name !startswith "pvc-"
| join kind=inner (
    resourcecontainers
    | where type == 'microsoft.resources/subscriptions'
    | project subscriptionId, subscriptionName = name)
    on subscriptionId 
| project name, diskState, managedBy, subscriptionName, resourceGroup, location

| where name !startswith "pvc-" : This line filters out disks whose names start with "pvc-".