Tags can be managed using PowerShell, Azure Resource Manager templates, portal, and REST API's. In this section, PowerShell will be used to create and apply tags. PowerShell provides a cmdlet for retrieving and attaching tags to resource groups and resources.
- To retrieve tags associated with a resource using PowerShell, the Find-AzureRMResource cmdlet can be used:
(Find-AzureRmResource -TagName Dept -TagValue Finance).Name
- To retrieve tags associated with a resource group using PowerShell, the following command can be used:
(Find-AzureRmResourceGroup -Tag @{ Dept="Finance" }).Name
- To set tags to a resource group, the Set-AzureRmResourceGroup cmdlet can be used:
Set-AzureRmResourceGroup -Name examplegroup -Tag @{ Dept="IT"; Environment="Test" }
- To set tags to a resource, the Set-AzureRmResource cmdlet can be used:
Set-AzureRmResource -Tag @{ Dept="IT"; Environment="Test" } -ResourceName examplevnet -ResourceGroupName examplegroup