Warm tip: This article is reproduced from stackoverflow.com, please click
azure azure-cli devops jmespath

Azure CLI query JMESPATH more then one expression

发布于 2020-06-12 10:22:51

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 :)

Questioner
Yuval Podoksik
Viewed
8
RoadRunner - MSFT 2020-03-29 01:46

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"