Can't set tag in Azure SQL Database using PowerShell
You can set the tag on an Azure resource such as a website using Set-AzureResource:
Set-AzureResource -Name [site name] -ResourceGroupName [resource group name] -ResourceType Microsoft.Web/sites -ApiVersion 2014-04-01 -Tags @{ Name = [my tag name]; Value = [my tag value] }
But no matter what I try, I cannot get this to work with Azure SQL DB. In fact, I can't even select a resource - here's what I'm trying:
Get-AzureResource -Name TroyPSTestDB -ResourceGroupName Default-SQL-WestUS -ResourceType Microsoft.Sql/servers -ApiVersion 2014-04-01
I always get "The resource provided does not exist". However, I can see the resource when I select all databases:
Get-AzureResource -ResourceGroupName Default-SQL-WestUS -ResourceType Microsoft.Sql/servers/databases
Which gives me:
Name : TroyPSTestDB
ResourceGroupName : Default-SQL-WestUS
ResourceType : Microsoft.Sql/servers/databases
ParentResource : servers/snyb5o1pxk
Location : westus
Permissions :
Actions NotActions
======= ==========
*
ResourceId : /subscriptions/62e2a1e5-4eda-4c1e-805e-44a6c8f8afbd/resourceGroups/Default-SQL-WestUS/providers/Microsoft.Sql/servers/snyb5o1pxk/databases/TroyPSTestDB
So what gives? Did something happen to the PS team? Or you just can't select one DB this way? Any other way to get the tag on it? Thank!
source to share
UPDATE: Not as many errors as received with the supplied arguments:
Get-AzureResource -Name {dbname} -ParentResource servers / {servername} -ResourceType Microsoft.Sql / servers / databases -ResourceGroupName {resource-group-name} -ApiVersion 2014-04-01
The key must include " servers / " in the -ParentResource argument.
So, in order to set the tags, you need to make sure you have configured the -ParentResource correctly - the rest of your arguments are correct.
===
You can add tags through the new portal. The Powershell stuff for managing this looks like a bug.
In the portal: /subscriptions/GUID/resourceGroups/Default-SQL-WestUS/providers/Microsoft.Sql/servers/ {servername} / databases / {database}? api-version = 2014-04-01
In PS: /subscriptions/GUID/resourcegroups/Default-SQL-WestUS/providers/Microsoft.Sql/ {servername} / databases / {database}? api-version = 2014-04-01
(note the missing node servers in the PS command).
Issue raised: https://github.com/Azure/azure-powershell/issues/73
source to share
With AzureRM.Resources 3.0.1, you can set tags in Sql database using the following syntax:
Set-AzureRmResource -ResourceType 'Microsoft.Sql/servers/databases' -ResourceName "$sqlServerName/$sqlDatabaseName" -ResourceGroupName $ressourceGroupName -Tag @{ env = "dev" }
In fact, the name of the Sql database resource returned Get-AzureRmResource
is already in the format server/database
.
source to share