Skip to content

Commit f5eb9c9

Browse files
committed
update
1 parent 2eabd9c commit f5eb9c9

File tree

1 file changed

+66
-26
lines changed

1 file changed

+66
-26
lines changed

articles/azure-resource-manager/management/tag-resources.md

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Tag resources, resource groups, and subscriptions for logical organization
33
description: Shows how to apply tags to organize Azure resources for billing and managing.
44
ms.topic: conceptual
5-
ms.date: 03/18/2020
5+
ms.date: 03/19/2020
66
---
77
# Use tags to organize your Azure resources, resource groups and subscriptions
88

@@ -28,7 +28,7 @@ The following example applies a set of tags to a storage account:
2828

2929
```azurepowershell-interactive
3030
$tags = @{"Dept"="Finance"; "Status"="Normal"}
31-
$resource = Get-AzResource -resourcename demoStorage -resourcegroup demoGroup
31+
$resource = Get-AzResource -Name demoStorage -ResourceGroup demoGroup
3232
New-AzTag -ResourceId $resource.id -Tag $tags
3333
```
3434

@@ -64,7 +64,7 @@ $tags = @{"Dept"="Finance"; "Status"="Normal"}
6464
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
6565
```
6666

67-
Notice all four tags have been applied to the resource.
67+
Notice that the two new tags were added to the two existing tags.
6868

6969
```output
7070
Properties :
@@ -76,6 +76,23 @@ Properties :
7676
Environment Production
7777
```
7878

79+
If you provide a new value for a tag and use the merge operation, the old value is replaced. The following example changes the Status tag from Normal to Green.
80+
81+
```azurepowershell-interactive
82+
$tags = @{"Status"="Green"}
83+
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
84+
```
85+
86+
```output
87+
Properties :
88+
Name Value
89+
=========== ==========
90+
Status Green
91+
Dept Finance
92+
Team Compliance
93+
Environment Production
94+
```
95+
7996
When you set the **-Operation** parameter to **Replace**, the existing tags are replaced by the new set of tags.
8097

8198
```azurepowershell-interactive
@@ -107,19 +124,46 @@ New-AzTag -ResourceId $resourceGroup.ResourceId -tag $tags
107124
To update the tags for a resource group, use:
108125

109126
```azurepowershell-interactive
110-
$tags = @{"Team"="Compliance"; "Environment"="Production"}
127+
$tags = @{"CostCenter"="00123"; "Environment"="Production"}
111128
$resourceGroup = Get-AzResourceGroup -Name demoGroup
112129
Update-AzTag -ResourceId $resourceGroup.ResourceId -Tag $tags -Operation Merge
113130
```
114131

115-
To add tags to a subscription, use:
132+
```output
133+
Properties :
134+
Name Value
135+
=========== ==========
136+
CostCenter 00123
137+
Environment Production
138+
Status Normal
139+
Dept Finance
140+
```
141+
142+
To add a new set of tags to a subscription, use:
116143

117144
```azurepowershell-interactive
118145
$tags = @{"CostCenter"="00123"; "Environment"="Dev"}
119146
$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
147+
New-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags
148+
```
149+
150+
To update the tags for a subscription, use:
151+
152+
```azurepowershell-interactive
153+
$tags = @{"Team"="Web Apps"}
154+
$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
120155
Update-AzTag -ResourceId "/subscriptions/$subscription" -Tag $tags -Operation Merge
121156
```
122157

158+
```output
159+
Properties :
160+
Name Value
161+
=========== ========
162+
Environment Dev
163+
CostCenter 00123
164+
Team Web Apps
165+
```
166+
123167
You may have more than one resource with the same name in a resource group. In that case, you can set each resource with the following commands:
124168

125169
```azurepowershell-interactive
@@ -133,56 +177,52 @@ To apply tags from a subscription or resource group to the resources, see [Azure
133177

134178
### List tags
135179

136-
To see the existing tags for a *resource group*, use:
137-
138-
```azurepowershell-interactive
139-
(Get-AzResourceGroup -Name examplegroup).Tags
140-
```
180+
To get the tags for a resource, resource group, or subscription, use the [Get-AzTag](/powershell/module/az.resources/get-aztag) command and pass in the entity.
141181

142-
That script returns the following format:
182+
To see the tags for a resource, use:
143183

144-
```output
145-
Name Value
146-
---- -----
147-
Dept IT
148-
Environment Test
184+
```azurepowershell-interactive
185+
$resource = Get-AzResource -Name demoStorage -ResourceGroup demoGroup
186+
Get-AzTag -ResourceId $resource.id
149187
```
150188

151-
To see the existing tags for a *resource that has a specified name and resource group*, use:
189+
To see the tags for a resource group, use:
152190

153191
```azurepowershell-interactive
154-
(Get-AzResource -ResourceName examplevnet -ResourceGroupName examplegroup).Tags
192+
$resourceGroup = Get-AzResourceGroup -Name demoGroup
193+
Get-AzTag -ResourceId $resourceGroup.ResourceId
155194
```
156195

157-
Or, if you have the resource ID for a resource, you can pass that resource ID to get the tags.
196+
To see the tags for a subscription, use:
158197

159198
```azurepowershell-interactive
160-
(Get-AzResource -ResourceId /subscriptions/<subscription-id>/resourceGroups/<rg-name>/providers/Microsoft.Storage/storageAccounts/<storage-name>).Tags
199+
$subscription = (Get-AzSubscription -SubscriptionName "Example Subscription").Id
200+
Get-AzTag -ResourceId "/subscriptions/$subscription"
161201
```
162202

163203
### List resources by tag
164204

165-
To get *resources that have a specific tag name and value*, use:
205+
To get resources that have a specific tag name and value, use:
166206

167207
```azurepowershell-interactive
168-
(Get-AzResource -Tag @{ "Dept"="Finance"}).Name
208+
(Get-AzResource -Tag @{ "CostCenter"="00123"}).Name
169209
```
170210

171-
To get *resources that have a specific tag name*, use:
211+
To get resources that have a specific tag name with any tag value, use:
172212

173213
```azurepowershell-interactive
174214
(Get-AzResource -TagName "Dept").Name
175215
```
176216

177-
To get *resource groups that have a specific tag name and value*, use:
217+
To get resource groups that have a specific tag name and value, use:
178218

179219
```azurepowershell-interactive
180-
(Get-AzResourceGroup -Tag @{ "Dept"="Finance" }).ResourceGroupName
220+
(Get-AzResourceGroup -Tag @{ "CostCenter"="00123" }).ResourceGroupName
181221
```
182222

183223
### Remove tags
184224

185-
To remove specific tags, use **Update-AzTag** and set **-Operation** to **Delete**.
225+
To remove specific tags, use **Update-AzTag** and set **-Operation** to **Delete**. Pass in the tags you want to delete.
186226

187227
```azurepowershell-interactive
188228
$removeTags = @{"Project"="ECommerce"; "Team"="Web"}

0 commit comments

Comments
 (0)