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

Get-AzureRmSqlDatabase?

Open ronbok opened this issue 10 years ago • 2 comments

Why doesn't Get-AzureRmSqlDatabase return an object? I was trying to grab a list of all the databases on a specific server instance and then check their audit and threat detection settings. What I get back isn't an object, but output from a what appears to be string collection?

After doing something like $Variable = Get-AzureRmSqlDatabase .... I want to iterate the collection of databases.

ronbok avatar Mar 18 '16 13:03 ronbok

In order to accomplish this I had to go way off the beaten path:

$Databases = Get-AzureRmResource -ResourceType "Microsoft.Sql/servers/databases" -ResourceGroupName "RGName" -ResourceName "DBServerName"

$Count = 1 While ($Count -le $Databases.Count) {

$Databases[$Count].Name $Count++

}

ronbok avatar Mar 18 '16 14:03 ronbok

The Get-AzureRMSqlDatabase cmdlet does return objects.

eg:

PS C:\Users\adamkr> $dbs = Get-AzureRmResourceGroup | Get-AzureRmSqlServer | Get-AzureRmSqlDatabase
PS C:\Users\adamkr> $dbs.Count
24
PS C:\Users\adamkr> $dbs[0].GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    AzureSqlDatabaseModel                    System.Object


PS C:\Users\adamkr> $dbs[0]


ResourceGroupName             : adamkr
ServerName                    : adamkr
DatabaseName                  : master
Location                      : West US
DatabaseId                    : d5d945b6-b09a-40cf-90a6-8a2853f98a8f
Edition                       : None
CollationName                 : SQL_Latin1_General_CP1_CI_AS
CatalogCollation              :
MaxSizeBytes                  : 5368709120
Status                        : Online
CreationDate                  : 9/11/2015 16:22:58
CurrentServiceObjectiveId     : 29dd7459-4a7c-4e56-be22-f0adda49440d
CurrentServiceObjectiveName   : System0
RequestedServiceObjectiveId   : 29dd7459-4a7c-4e56-be22-f0adda49440d
RequestedServiceObjectiveName :
ElasticPoolName               :
EarliestRestoreDate           : 1/1/0001 00:00:00
Tags                          :
ResourceId                    : /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/adamkr/providers/Mic
                                rosoft.Sql/servers/adamkr/databases/master
CreateMode                    :

akromm-zz avatar Jan 09 '17 18:01 akromm-zz