Script Sample - Set Tags on Azure Resources

@20aman    Nov 07, 2018

Earlier we fetches the Azure resources report with the Tagging related information. You can review that script to fetch the report here: Script Sample - Generate Azure Resources Report by Tags v3.0

The output CSV generate by that script can be updated. It can be corrected for missing tag values or incorrect tag values, etc. The updated csv then can become an Input to the script sample discussed in this blog. This script will read from the updated CSV file and will apply the tags back to the Azure.

Note: This script takes lot of time because the underlying cmdlet takes lot of time to set the tags (i.e. "Set-AzureRmResource" cmdlet). So it is advised that you filter to only the resources for which you want to update the tags.

Script Workings

As mentioned earlier, this script inputs the CSV file generated earlier. The schema for this input file can be checked from the output of Get script from the link mentioned above.

The script then connects to Azure and updates the Tags. If the Tags were not present already then it adds the tagging information. It uses the below command to update the tags.

Set-AzureRmResource -Tag $r.Tags -ResourceId $r.ResourceId -Force

Location of the Script

You can find this script in GitHub at this location: Set-AzureRmTags.ps1





Comments powered by Disqus