Update-AzTag Operation Delete not working for disks. Iam executing this in powershell.Tags in all others resources such as VM, Vnet are getting deleted except Disk

Naveen Yadav 1 Reputation point
2022-07-21T15:38:21.047+00:00

Update-AzTag Operation Delete not working for disks. Iam executing this in powershell.Tags in all others resources such as VM, Vnet are getting deleted except Disk
Update-AzTag operation Merge is working fine for disk for inserting new tags but delete operation is not working for only disk in case we want to delete some specific tag

Receiving below error:
Update-AzTag : Operation returned an invalid status code 'Accepted'
At C:\Users\navee\Desktop\test.ps1:52 char:9

  • Update-AzTag -ResourceId $resourceID -Tag $resourcedeleteTag ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  • CategoryInfo : CloseError: (:) [Update-AzTag], CloudException
  • FullyQualifiedErrorId : Microsoft.Azure.Commands.Tags.Tag.UpdateAzureTagCommand

Code which I am trying to execute, working for all resources except Disk:
Get-AzResource -ResourceGroupName "$resourceGroupName" | ForEach-Object{

$resource = $_.Name  
$resourceType = $_.ResourceType  
$resourceID = $_.ResourceId  


if(![string]::IsNullOrEmpty($_.Tags)){  
    $_.Tags.GetEnumerator() |ForEach-Object{  

        $resource_currentKey = $_.key  
        $resource_value = $_.value  

 # checking if Tag key contains blankspace.. then remove blank space and update tag key again without blankspace         
if($resource_currentKey.contains(" ")){  
    $resource_newKey = $resource_currentKey.replace(' ','')  
    $resourcedeleteTag = @{"$resource_currentKey"="$resource_value"}  
    $resourcenewTag = @{"$resource_newKey"="$resource_value"}  
    Update-AzTag -ResourceId $resourceID -Tag $resourcedeleteTag -Operation Delete      
    echo "Deleted $resource_currentKey : $resource_value in resource $resource "  
    Update-AzTag -ResourceId $resourceID -Tag $resourcenewTag -Operation Merge  
    echo "new tag added $resource_newKey : $resource_value in resource $resource"  
}  

}
}
}

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
40,353 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.