4

I'm trying to add multiple tags through a variable using Azure-CLI (using Powershell Core).

az resource tag --tags ${tagsToAdd} --id $resource.id

Where $tagsToAdd="a=b c=d"

But this gives me only one tag :

"tags": {
    "a": "b c=d"
    } 

What is wrong with this? Using az resource tag --tags a=b c=d --id $resource.id correctly produces two tags.

1 Answer 1

8

You could use it as below.

$tagsToAdd=@("a=b","c=d")
az resource tag --tags ${tagsToAdd} --id $resource.id

enter image description here

2
  • Never though I could use an array to pass those parameters looking at the documentation. Thanks!
    – Loki
    Dec 6, 2019 at 8:05
  • Great answer. Just want to highlight this works also where the tag's name or the tag's value have spaces. Other solutions tend to trip where the name or the value has a space in it.
    – LordHits
    Jan 12, 2021 at 18:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.