0

Command az resource list --resource-group MYRG --query "[].{type:type}"

output

[
{
"type": "Microsoft.Network/networkInterfaces"
},
{
"type": "Microsoft.Network/networkInterfaces"
},
{
"type": "Microsoft.Network/networkSecurityGroups"
},
{
"type": "Microsoft.Network/networkSecurityGroups"
}
]

Tried below command but no luck

$ az resource list --resource-group MYRG --query [? type == "Microsoft.Web/serverFarms"] bash: Microsoft.Web/serverFarms: No such file or directory argument --query: invalid jmespath_type value: '[?' To learn more about --query, please visit: 'https://learn.microsoft.com/cli/azure/query-azure-cli'

Uday Kiran
  • 487
  • 2
  • 9
  • 29

1 Answers1

1

az resource list --resource-group MYRG --query "[].{type:type}"

you might have multiple resources of same resource type under the specific resource group would suggest you to list the resources by adding another filter like name & type as shown in the below & check the cmdlet is giving any duplicate values

az resource list --resource-group <resource-groupname> --query "[].{type:type,name:name}"

$ az resource list --resource-group MYRG --query [? type == "Microsoft.Web/serverFarms"]

looks like there is an syntactical error in the above command can you try the below command to list resource which are of type 'Microsoft.Web/serverFarms' under a resource group.

az resource list --resource-group <resource-groupname> --query "[?type == 'Microsoft.Web/serverFarms'].{name:name,type:type}"`

Here is the reference document to filter the array using AzureCLI

Note: In JMESPath, strings are always surrounded by single quotes ('). If you use double quotes as part of a string in a filter predicate, you'll get empty output.

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12