query-azure-cli-examples.md

August 28, 2025 ยท View on GitHub

This section contains examples of JMESPath queries for different Azure resources.

Query examples for Azure accounts

This section shows example queries for storage accounts.

  • This example returns the tenant ID and subscription ID of the Azure account and subscription you're using.

Bash

az account show --query "{tenantId:tenantId,subscriptionid:id}"

PowerShell

az account show --query "{tenantId:tenantId,subscriptionid:id}"

Cmd

az account show --query "{tenantId:tenantId,subscriptionid:id}"

Query examples for Microsoft Entra service principals

This section shows example queries for Microsoft Entra service principals.

  • The following query returns the first Microsoft Graph application service principal who has read permissions.

Bash

az ad sp list --display-name "Microsoft Graph" --query "[0].appRoles[?value=='User.Read.All' && contains(allowedMemberTypes, 'Application')].id" --output tsv

PowerShell

az ad sp list --display-name "Microsoft Graph" --query "[0].appRoles[?value=='User.Read.All' && contains(allowedMemberTypes, 'Application')].id" --output tsv

Cmd

az ad sp list --display-name "Microsoft Graph" --query "[0].appRoles[?value=='User.Read.All' && contains(allowedMemberTypes, 'Application')].id" --output tsv

Query examples for storage accounts

This section shows example queries for storage accounts.

  • This example returns the primary endpoints for all tables a storage account.

Bash

az storage account show --resource-group QueryDemo --name mystorageaccount --query "primaryEndpoints.table"

PowerShell

az storage account show --resource-group QueryDemo --name mystorageaccount --query "primaryEndpoints.table"

Cmd

az storage account show --resource-group QueryDemo --name mystorageaccount --query "primaryEndpoints.table"

Query examples for Virtual Machines

This section shows example queries for Virtual Machines (VMs).

  • This example returns the names of VMs whose disk size is larger than 50 GB.

Bash

az vm list --resource-group QueryDemo --query "[?storageProfile.osDisk.diskSizeGb >=\`50\`].{Name:name,  admin:osProfile.adminUsername, DiskSize:storageProfile.osDisk.diskSizeGb }" --output table

PowerShell

az vm list --resource-group QueryDemo --query "[?storageProfile.osDisk.diskSizeGb >=``50``].{Name:name,  admin:osProfile.adminUsername, DiskSize:storageProfile.osDisk.diskSizeGb }" --output table

Notice the extra escape characters (`) surrounding the 50 in the command previous. The extra escape characters are present because Azure CLI commands are considered Command Prompt scripts. Take into consideration the built-in parsing of both PowerShell and of a Command Prompt. Azure CLI will only receive a symbol if it still exists after 2 rounds of parsing. For more information about other possible quoting issues in PowerShell, see Considerations for running the Azure CLI in a PowerShell scripting language.

Cmd

az vm list --resource-group QueryDemo --query "[?storageProfile.osDisk.diskSizeGb >=`50`].{Name:name, admin:osProfile.adminUsername, DiskSize:storageProfile.osDisk.diskSizeGb }" --output table

  • The following query demonstrates how to list the names and storage account types of VMs who use SSD storage.

Bash

az vm list --resource-group QueryDemo --query "[].{Name:name, Storage:storageProfile.osDisk.managedDisk.storageAccountType} | [? contains(Storage,'SSD')]"

PowerShell

az vm list --resource-group QueryDemo --query "[].{Name:name, Storage:storageProfile.osDisk.managedDisk.storageAccountType} | [? contains(Storage,'SSD')]"

Cmd

az vm list --resource-group QueryDemo --query "[].{Name:name, Storage:storageProfile.osDisk.managedDisk.storageAccountType} | [? contains(Storage,'SSD')]"

Query examples for cognitive services

This section shows example queries for cognitive services.

  • The following query demonstrates how to list endpoints of a cognitive service.

Bash

az cognitiveservices account show --resource-group QueryDemo --name DemoAccount --query "properties.endpoint"

PowerShell

az cognitiveservices account show --resource-group QueryDemo --name DemoAccount --query "properties.endpoint"

Cmd

az cognitiveservices account show --resource-group QueryDemo --name DemoAccount --query "properties.endpoint"


Query examples for virtual networks

This section shows example queries for virtual networks (VNet).

  • The following query lists the IDs of IP addresses that contain the substring in the variable IP.

Bash

IP="20.127"
az network public-ip list --query "[?ipAddress!=null]|[?contains(ipAddress, '$IP')].[id]" --output tsv

PowerShell

$IP="20.127"
az network public-ip list --query "[?ipAddress!=null]|[?contains(ipAddress, '$IP')].[id]" --output tsv

Cmd

Set IP="20.127"
az network public-ip list --query "[?ipAddress!=null]|[?contains(ipAddress, '%IP%')].[id]" --output tsv

Query examples for web apps

This section shows example queries for web apps.

  • The following query lists all web apps that are currently running.

Bash

az webapp list --resource-group DemoGroup --query "[?state=='Running']"

PowerShell

az webapp list --resource-group DemoGroup --query "[?state=='Running']"

Cmd

az webapp list --resource-group DemoGroup --query "[?state=='Running']"

  • The following query returns the profile name and url of all web apps whose profile name ends with FTP.

Bash

az webapp deployment list-publishing-profiles --resource-group DemoGroup --name DemoApp --query "[?ends_with(profileName, 'FTP')].{profileName: profileName, publishUrl: publishUrl}"

PowerShell

az webapp deployment list-publishing-profiles --resource-group DemoGroup --name DemoApp --query "[?ends_with(profileName, 'FTP')].{profileName: profileName, publishUrl: publishUrl}"

Cmd

az webapp deployment list-publishing-profiles --resource-group DemoGroup --name DemoApp --query "[?ends_with(profileName, 'FTP')].{profileName: profileName, publishUrl: publishUrl}"