@@ -200,7 +200,7 @@ az resource tag --tags Dept=IT Environment=Test -g examplegroup -n examplevnet -
200
200
To add tags to a resource that already has tags, retrieve the existing tags, reformat that value, and reapply the existing and new tags:
201
201
202
202
``` azurecli
203
- jsonrtag=$(az resource show -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks" --query tags)
203
+ jsonrtag=$(az resource show -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks" --query tags -o json )
204
204
rt=$(echo $jsonrtag | tr -d '"{},' | sed 's/: /=/g')
205
205
az resource tag --tags $rt Project=Redesign -g examplegroup -n examplevnet --resource-type "Microsoft.Network/virtualNetworks"
206
206
```
@@ -211,7 +211,7 @@ To apply all tags from a resource group to its resources, and *not keep existing
211
211
groups=$(az group list --query [].name --output tsv)
212
212
for rg in $groups
213
213
do
214
- jsontag=$(az group show -n $rg --query tags)
214
+ jsontag=$(az group show -n $rg --query tags -o json )
215
215
t=$(echo $jsontag | tr -d '"{},' | sed 's/: /=/g')
216
216
r=$(az resource list -g $rg --query [].id --output tsv)
217
217
for resid in $r
@@ -227,12 +227,12 @@ To apply all tags from a resource group to its resources, and *keep existing tag
227
227
groups=$(az group list --query [].name --output tsv)
228
228
for rg in $groups
229
229
do
230
- jsontag=$(az group show -n $rg --query tags)
230
+ jsontag=$(az group show -n $rg --query tags -o json )
231
231
t=$(echo $jsontag | tr -d '"{},' | sed 's/: /=/g')
232
232
r=$(az resource list -g $rg --query [].id --output tsv)
233
233
for resid in $r
234
234
do
235
- jsonrtag=$(az resource show --id $resid --query tags)
235
+ jsonrtag=$(az resource show --id $resid --query tags -o json )
236
236
rt=$(echo $jsonrtag | tr -d '"{},' | sed 's/: /=/g')
237
237
az resource tag --tags $t$rt --id $resid
238
238
done
0 commit comments