How to bulk update Tags with wrong casing

DeHaven Graham 101 Reputation points
2022-08-01T19:53:39.1+00:00

Is there anyway to bulk update Azure tags just based off case sensitivity for i.e change "testTest" to TestTest"? I'm trying to do this in powershell but it's not allowing me since tags are case insesitive in Azure. Any advice would be helpful.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,792 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,359 questions
0 comments No comments
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 19,686 Reputation points
    2022-08-04T12:06:37.583+00:00

    Hi @DeHaven Graham ,

    Thank you for posting this question on Microsoft Q&A.

    I understand that you are trying to update Tag Names in bulk (by only changing the case of contained letters) for resources in your resource group/subscription.

    Please note that Tag Names are case insensitive, but tag values are case sensitive. That is why you cannot update the TagName without deleting the tag Name/value pair if you are only updating the case of Tag name (changing 'test' to 'Test' ).

    You can use Update-AzTag to achieve this, but it will require both operations of this cmdlet - "Delete" and "Merge". Please see this link for more details. As a sample, I am providing the script below which updates the casing of a particular TagName for all resources in a resource group.
    Note: The script below is for demo purpose only and provided as-is, without any warranty. Please test the script before using it in production.

    #assuming that the tagName and value are @{'test'='someValue'}  
    #and this needs to be changed to @{'Test'='someValue'}  #---note that only the tag name has been updated. The value is preserved  
      
    $old_TagName = 'test'  #Tag name with lowercase 't'  
    $new_TagName = 'Test'  #The new tag n  
      
    #Scope for the operation. In this case, all resources of a resource group.  
    $RESOURCE_GROUP = 'test-resourceGroup'   
      
    #Get all the resources from a resource group  
    $resources = Get-AzResource -ResourceGroupName 'test-resourceGroup'  
      
    $tempVal = ""  
      
    foreach($resource in $resources)  
    {  
        if($resource.Tags.ContainsKey($old_TagName))   
        {  
            $tempVal = $resource.Tags[$old_TagName]  
          
            $deletedTags = @{$old_TagName = $tempVal}  
      
            #update-Tag with DELETE operation  
            $null = Update-AzTag -ResourceId $resource.ResourceId -Tag $deletedTags -Operation Delete  
      
            Write-Output "Updating for                  : $($resource.Name)"  
            Write-Output "Old Tag Name and Value        : {$old_TagName : $tempVal}"  
            Write-Output "Updated Tag Name and Value    : {$new_TagName : $tempval}"  
            Write-Output "---------------------------------------------------------"  
            $mergedTags = @{$new_TagName = $tempVal}  
      
            #Update-Tag with MERGE Operation  
            $null = Update-AzTag -ResourceId $resource.ResourceId -Tag $mergedTags -Operation Merge  
      
            $tempVal = ""  #reset the tag value  
        }  
    }  
    

    Please let me know if you have any questions.

    ---
    Please 'Accept as answer' if it helped so that it can help others in the community looking for help on similar topics.


1 additional answer

Sort by: Most helpful
  1. Limitless Technology 39,341 Reputation points
    2022-08-03T07:17:44.707+00:00

    Hi there,

    When you need to add or modify many work items, using Microsoft Excel can save you time. Excel supports adding work items, updating existing work items, adding links and attachments to multiple work items, and more.

    Add or modify Azure Boards work items in bulk with Microsoft Excel https://learn.microsoft.com/en-us/azure/devops/boards/backlogs/office/bulk-add-modify-work-items-excel?view=azure-devops&tabs=agile-process

    You can refer the below thread which sheds some insights about this .
    Consolidating and editing Azure Tags in bulk with no data loss or outage https://learn.microsoft.com/en-us/answers/questions/136893/consolidating-and-editing-azure-tags-in-bulk-with.html

    I hope this information helps. If you have any questions please let me know and I will be glad to help you out.

    --------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments