0

I would like to know if a value in a TXT record is already available in the DNS:

az network dns record-set txt show -g myresourcegroup -z 'mydomain' -n 'mytxtvalues'

This is the part of the json result where it's all about:

 "txtRecords": [
    {
      "value": [
        "abc"
      ]
    },
    {
      "value": [
        "def"
      ]
    }
  ]

I tried many queries. These are 2 which I expected to work.

az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query txtRecords[?value[?starts_with(@, 'abc')]]

az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query txtRecords[*].value[?starts_with(@, 'abc')]]

The result is:

At line:1 char:123 + ... 'mytxtvalues' --query txtRecords[?value[?starts_with(@, 'abc') ... + ~ Unrecognized token in source text. At line:1 char:124 + ... 'mytxtvalues' --query txtRecords[?value[?starts_with(@, 'abc')] ... + ~ Missing argument in parameter list.

It looks like the @ used to filter the array is not recognized. But I don't know how to query otherwise.

What would be a correct query to know if value abc is already in the list?

Pascal Naber
  • 1,092
  • 8
  • 14

1 Answers1

2

You need to use the command like this:

az network dns record-set txt show -g myresourcegroup -z 'mydomain.com' -n 'mytxtvalues' --query "txtRecords[*].value[?starts_with(@, 'abc')]"

And if you just need to output the string you can append the parameter -o tsv. Hope this will help you.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39