Introduction
In this blog, you will see how to add tags to Azure Storage Account resources using PowerShell.
Tags are name/value pairs that enable you to categorize resources and view consolidated billing by applying the same tag to multiple resources and resource groups. Tag names are case-insensitive and tag values are case-sensitive.
Click here to learn more about tagging Azure resources.
Prerequisites
Install Azure PowerShell Module to run the script.text
PowerShell Script
Open Notepad and paste the following script. Save the file as script.ps1.
- ################# Azure Blob Storage - PowerShell ####################
-
- ## Input Parameters
- $resourceGroupName="azpractice"
- $resourceName="azstorageacc1122020"
-
- ## Connect to Azure Account
- Connect-AzAccount
-
- ## Function to add and retrieve tags
- Function Tags
- {
- Write-Host -ForegroundColor Green "Adding the tag to Azure Storage Account resource..."
-
- ## Add tag to Azure Storage Account resource
- $resource = Get-AzResource -ResourceName $resourceName -ResourceGroupName $resourceGroupName
- Set-AzResource -Tag @{ "Dept"="Finance"; "Environment"="Developement" } -ResourceId $resource.ResourceId -Force
-
- Write-Host -ForegroundColor Green "Display all tags for specific resource..."
-
- ## Display all tags
- (Get-AzResource -ResourceName $resourceName -ResourceGroupName $resourceGroupName).Tags
- }
-
- Tags
-
- ## Disconnect from Azure Account
- Disconnect-AzAccount
Open Windows PowerShell window and navigate to the location where the script file was saved.
Run the following command.
.\script.ps1
Result
Summary
Thus, in this blog, you saw how to add tags to Azure Storage Account resources using PowerShell.