azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Unable to set Tags through New-AzureRmSqlServer

Open Vijayaraghavanl opened this issue 10 years ago • 1 comments

Unable to set Tags through Powershell for Azure SQL Server and Azure SQL Database:

I am creating Azure SQL Server and Database through powershell and all inputs to powershell are through a csv file.

Below is a part of the code. $CSVInput = Import-Csv $CSVFile

ForEach($InputObj in $CSVInput) { $SQLSvrResourceGroupName = $InputObj.SQLSvrResourceGroupName $SQLServerName = $InputObj.SQLServerName $Location = $InputObj.Location $BusinessUnit = $InputObj.BusinessUnit $Projectcode = $InputObj.ProjectCode $PrimaryContact = $InputObj.PrimaryContact $SecondaryContact = $InputObj.SecondaryContact $RequestNo = $InputObj.RequestNo $StartDate = $InputObj.StartDate $EndDate = $InputObj.EndDate $Tags = @(@{Name = "Business Unit"; Value = $BusinessUnit}, @{Name = "Project Code"; Value = $ProjectCode}, @{Name = "Primary Contact"; Value = $PrimaryContact}, @{Name = "Secondary Contact"; Value = $SecondaryContact}, @{Name = "Request No"; Value = $RequestNo}, @{Name = "Start Date"; Value = $StartDate}, @{Name = "End Date"; Value = $EndDate})

New-AzureRmResourceGroup -Name $SQLSvrResourceGroupName -Location $Location -Tag $Tags

New-AzureRmSqlServer -ResourceGroupName $SQLSvrResourceGroupName -ServerName $SQLServerName -Location $Location -ServerVersion $SQLServerVersion -SqlAdministratorCredentials $Credential -Tags $Tags

}

While Tags get set correctly for the Resource Group it fails for both New-AzureRmSqlServer as well as New-AzureRmSqlDatabase with the below error:

New-AzureRmSqlDatabase : Cannot convert 'System.Object[]' to the type 'System.Collections.Generic.Dictionary`2[System.String,System.String]' required by parameter 'Tags'. Specified method is not supported. At C:\Users\Vijay\Desktop\Scripts\Azure SQL ARM\Azure SQL ARM v1.0.ps1:113 char:395

  • ... n -RequestedServiceObjectiveName $DatabasePerfomanceLevel -Tags $Tags
  •                                                                 ~~~~~
    
    • CategoryInfo : InvalidArgument: (:) [New-AzureRmSqlDatabase], ParameterBindingException
    • FullyQualifiedErrorId : CannotConvertArgument,Microsoft.Azure.Commands.Sql.Database.Cmdlet.NewAzureSqlDatabase

Please advise how to specify Tags for SQL server and SQL database.

Vijayaraghavanl avatar Mar 22 '16 16:03 Vijayaraghavanl

Fixed Tags overall in #3206.

jamestao avatar Nov 17 '16 20:11 jamestao