2
2
title : Tag resources, resource groups, and subscriptions with Azure PowerShell
3
3
description : Shows how to use Azure PowerShell to apply tags to Azure resources.
4
4
ms.topic : conceptual
5
- ms.date : 04/11 /2023
5
+ ms.date : 04/19 /2023
6
6
---
7
7
8
8
# Apply tags with Azure PowerShell
@@ -37,6 +37,7 @@ If you run the command again, but this time with different tags, notice that the
37
37
38
38
``` azurepowershell-interactive
39
39
$tags = @{"Team"="Compliance"; "Environment"="Production"}
40
+ $resource = Get-AzResource -Name demostorage -ResourceGroup demoGroup
40
41
New-AzTag -ResourceId $resource.id -Tag $tags
41
42
```
42
43
@@ -52,6 +53,7 @@ To add tags to a resource that already has tags, use `Update-AzTag`. Set the `-O
52
53
53
54
``` azurepowershell-interactive
54
55
$tags = @{"Dept"="Finance"; "Status"="Normal"}
56
+ $resource = Get-AzResource -Name demostorage -ResourceGroup demoGroup
55
57
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
56
58
```
57
59
@@ -71,6 +73,7 @@ Each tag name can have only one value. If you provide a new value for a tag, it
71
73
72
74
``` azurepowershell-interactive
73
75
$tags = @{"Status"="Green"}
76
+ $resource = Get-AzResource -Name demostorage -ResourceGroup demoGroup
74
77
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Merge
75
78
```
76
79
@@ -88,6 +91,7 @@ When you set the `-Operation` parameter to `Replace`, the new set of tags replac
88
91
89
92
``` azurepowershell-interactive
90
93
$tags = @{"Project"="ECommerce"; "CostCenter"="00123"; "Team"="Web"}
94
+ $resource = Get-AzResource -Name demostorage -ResourceGroup demoGroup
91
95
Update-AzTag -ResourceId $resource.id -Tag $tags -Operation Replace
92
96
```
93
97
@@ -194,6 +198,7 @@ To remove specific tags, use `Update-AzTag` and set `-Operation` to `Delete`. Pa
194
198
195
199
``` azurepowershell-interactive
196
200
$removeTags = @{"Project"="ECommerce"; "Team"="Web"}
201
+ $resource = Get-AzResource -Name demostorage -ResourceGroup demoGroup
197
202
Update-AzTag -ResourceId $resource.id -Tag $removeTags -Operation Delete
198
203
```
199
204
0 commit comments