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.

  1. ################# Azure Blob Storage - PowerShell ####################
  2. ## Input Parameters
  3. $resourceGroupName="azpractice"
  4. $resourceName="azstorageacc1122020"
  5. ## Connect to Azure Account
  6. Connect-AzAccount
  7. ## Function to add and retrieve tags
  8. Function Tags
  9. {
  10. Write-Host -ForegroundColor Green "Adding the tag to Azure Storage Account resource..."
  11. ## Add tag to Azure Storage Account resource
  12. $resource = Get-AzResource -ResourceName $resourceName -ResourceGroupName $resourceGroupName
  13. Set-AzResource -Tag @{ "Dept"="Finance"; "Environment"="Developement" } -ResourceId $resource.ResourceId -Force
  14. Write-Host -ForegroundColor Green "Display all tags for specific resource..."
  15. ## Display all tags
  16. (Get-AzResource -ResourceName $resourceName -ResourceGroupName $resourceGroupName).Tags
  17. }
  18. Tags
  19. ## Disconnect from Azure Account
  20. 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.