1

I was wondering if anybody can provide some insight into getting a list of databases from a FailoverGroup. I am half way there but when iterating over the databases within a FailoverGroup, the databases are a bunch of strings (https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.sql.models.failovergroup.databases?view=azure-dotnet). I want to convert this into a database object but because this is represented as a fully qualified name this is proving to be a little difficult to do unless I start splitting the string and indexing parts of it.

For example, the database name is returned as /subscriptions/[subscription_id]/resourceGroups/[resource_group]/providers/Microsoft.Sql/servers/[sql_server]/databases/MyDatabaseName

When I use the cmdlet Get-AzureRmSqlDatabase passing the above string, it doesn't place nice saying it doesn't exist. I can get this to work if I were to split the string and extract the database name only but that seems a little overkill.

In a nutshell, is there a way to cast the value returned in FailoverGroup.Databases to an instance of Microsoft.Azure.Commands.Sql.Database.Model.AzureSqlDatabaseModel

I am using the following to get fail over groups if this helps.. Get-AzureRmSqlDatabaseFailoverGroup -ResourceGroupName $ResourceGroupName -ServerName $ServerName

2
  • Do you want to get database within a failovergroup by using Azure CLI 2.0 or 1.0? Commented Nov 7, 2017 at 2:34
  • @Walter-MSFT using version 2.0 Commented Nov 7, 2017 at 8:56

2 Answers 2

3

Based on my knowledge, currently, Azure CLI 2.0 does not support get failover group information. You could check official document.

You could use Rest API to get it.

GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/failoverGroups/{failoverGroupName}?api-version=2015-05-01-preview
Sign up to request clarification or add additional context in comments.

1 Comment

@Dr Schizo In your scenario, rest api maybe is a good solution. If you want more future help, please let me know.
0

Using powershell:

Get-AzureRmResource -ApiVersion 2014-04-01 -ResourceId /subscriptions/[subscription_id]/resourceGroups/[resource_group]/providers/Microsoft.Sql/servers/[sql_server]/databases/MyDatabaseName

Using Azure CLI:

az resource show --api-version 2014-04-01 --ids /subscriptions/[subscription_id]/resourceGroups/[resource_group]/providers/Microsoft.Sql/servers/[sql_server]/databases/MyDatabaseName

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.