How to add Tags to an Azure Storage Account using PowerShell

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