Search code examples
azurepowershellazure-devopsazure-cliazure-appservice

Azure cli - List all webapps where https-only is disabled


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.


Solution

  • 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 either true or false. Expressions where the predicate evaluates to true 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:

    az cli output

    This seems to show the query works.