Share via

Adding tags to a SqL DB with powershell AZ

Debbie Edwards 521 Reputation points
Mar 2, 2023, 11:42 AM

Im trying to us Powershell to create tags for SQL database and Server but the only thing I can find is the following

Set-AzureRmResource -ResourceType 'Microsoft.Sql/servers/databases' -ResourceName "$serverName/$databaseName" -ResourceGroupName $RG -Tag @{ 'applicationName' = 'SQL DB'; 'businessProcess' = "Post Project"}

However this uses AzureRM and not Az. I believe that AzureRM is old and we need to now use Az but I cant seem to find any updated information

Does anyone know how do do this using Az?

Azure SQL Database
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,872 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 118.9K Reputation points MVP
    Mar 2, 2023, 11:47 AM

    Hi @Debbie Edwards ,

    the migration of AzureRM scripts/commands is easy in most cases. Just replace AzureRMwith AZ.

    This should work with the AZ module:

    Set-AzResource -ResourceType 'Microsoft.Sql/servers/databases' -ResourceName "$serverName/$databaseName" -ResourceGroupName $RG -Tag @{ 'applicationName' = 'SQL DB'; 'businessProcess' = "Post Project"}
    
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. ShaktiSingh-MSFT 16,266 Reputation points
    Mar 2, 2023, 12:02 PM

    Hi @Debbie Edwards ,

    Thanks for posting this question in Microsoft Q&A forum.

    As I understand from the question, you want to add tags to Azure SQL Database using Powershell commands.

    Set-AzureRmResource is used to apply tag(other properties) at Resource Group level.

    If you have an existing Database, and want to add tags to it, please use below syntax:

    Set-AzSqlDatabase
       [-DatabaseName] <String>
       [-MaxSizeBytes <Int64>]
       [-Edition <String>]
       [-RequestedServiceObjectiveName <String>]
       [-ElasticPoolName <String>]
       [-ReadScale <DatabaseReadScale>]
       [-Tags <Hashtable>]
       [-ZoneRedundant]
       [-AsJob]
       [-LicenseType <String>]
       [-ComputeModel <String>]
       [-AutoPauseDelayInMinutes <Int32>]
       [-MinimumCapacity <Double>]
       [-HighAvailabilityReplicaCount <Int32>]
       [-BackupStorageRedundancy <String>]
       [-SecondaryType <String>]
       [-MaintenanceConfigurationId <String>]
       [-PreferredEnclaveType <String>]
       [-ServerName] <String>
       [-ResourceGroupName] <String>
       [-DefaultProfile <IAzureContextContainer>]
       [-WhatIf]
       [-Confirm]
       [<CommonParameters>]
    

    Here, Tags could be used to add tags in the existing Azure SQL Database.

    Reference Link: Set-AzSqlDatabase

    Hope this helps. Please let us know if I have answered correctly to the ask as per my understanding or you have a different question which needs to be addressed.

    Let us know if you face any issue in command execution.

    Thank you.

    0 comments No comments

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.