I am using azure cli to fetch all the webapps
az webapp list --query '[].{Name:name}'
It's working fine but I want to query so that it only returns webapps whose "https only" setting is disabled. How can I query that? I tried az webapp list --query '[?httpsonly==false].{Name:name}'
but that didn't work.
You can query Azure CLI command output using a JMESPath query.
The Azure CLI uses the
--query
argument to execute a JMESPath query on the results of commands. JMESPath is a query language for JSON, giving you the ability to select and modify data from CLI output. Queries are executed on the JSON output before any display formatting.
Since you're looking to filter results, have a look at how you can filter arrays.
The other operation used to get data from an array is filtering. Filtering is done with the
[?...]
JMESPath operator. This operator takes a predicate as its contents. A predicate is any statement that can be evaluated to eithertrue
orfalse
. Expressions where the predicate evaluates totrue
are included in the output.
In the end, you were pretty close. The JMESPath already parses booleans, and property names are case sensitive.
This would make the command to list the names of all web apps that have the httpOnly
property set to false something like this:
az webapp list --query '[?!httpsOnly].{Name:name}'
EDIT:
Here's an example of the output I get when retrieving all web apps without and with httpsOnly
set to true respectively from one of my personal tenants:
This seems to show the query works.