Search code examples
azuredevopsazure-clijmespath

Azure CLI query JMESPATH more then one expression


I'm trying to list all unmanaged disks in a specific resource group in my account inside Azure cloud provider that not have a specific tag, but having issues with the query part.

The command above lists all unmanaged disks:

az disk list -g $rgName --query [?managedBy=='null'].name -o tsv

When writing the command above, I'm not getting any output (although I have unmanaged disks that don't have tags.Action equals to 'ToDelete':

az disk list -g $rgName --query "[?(managedBy=='null') && (tags.Action!='ToDelete')].name" -o tsv

Thank you for the help :)


Solution

  • I believe the issue is because you are comparing against the string 'null' instead of null. This will cause you to recieve an empty array [] as the result.

    This works for me:

    az disk list -g $rgName --query "[?(managedBy==null) && (tags.Action!='ToDelete')].name"