0

I want to filter out two types in the query expression

Json file :

[
   {
    "name": "name0",
    "tags": {
      "env": "dev"
    },
    "type": "Microsoft.OperationsManagement/solutions"
  },
  {
    "name": "name1",
    "tags": {
      "env": "dev"
    },
    "type": "Microsoft.Web/sites"
  },
  {
    "name": "name2",
    "tags": {
      "env": "dev"
    },
    "type": "Microsoft.Web/serverFarms"
  },
  {
    "name": "name4",
    "tags": null,
    "type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks"
  }
]

Expression

az resource list  --resource-group MYRG --query '[? type != `"Microsoft.OperationsManagement/solutions"` && `"Microsoft.Network/privateDnsZones/virtualNetworkLinks"`]'

But result is including 2nd type in the result

[
  {
    "name": "name1",
    "tags": {
      "env": "dev"
    },
    "type": "Microsoft.Web/sites"
  },
  {
    "name": "name2",
    "tags": {
      "env": "dev"
    },
    "type": "Microsoft.Web/serverFarms"
  },
  {
    "name": "name4",
    "tags": null,
    "type": "Microsoft.Network/privateDnsZones/virtualNetworkLinks"
  }
]

I have tried other expression but no luck. Could someone tell me what exactly I am missing.

Uday Kiran
  • 487
  • 2
  • 9
  • 29

1 Answers1

1

You can try adding another type != after &&:

az resource list  --resource-group MYRG --query '[? type != `"Microsoft.OperationsManagement/solutions"` && type != `"Microsoft.Network/privateDnsZones/virtualNetworkLinks"`]'

You can also filter using slice to exclude "Microsoft.OperationsManagement/solutions" and "Microsoft.Network/privateDnsZones/virtualNetworkLinks":

az resource list --resource-group MYRG --query [1:3].type

You can refer to How to query Azure resources using the Azure CLI and JMESPATH queries

Ecstasy
  • 1,866
  • 1
  • 9
  • 17