Hi there,
Like many I have needed to Automate certain tasks across several databases, (in this instance the databases are all part of a single elastic database pool). My first task was to schedule the rebuilding of database indexes, however the 'elastic jobs' are complex in it's setup and doesn't allow for changes such as additional databases being added, without having to make changes to each individual database when they are created or added, as this is a frequent occurrence for me I then looked at an Azure Automation account, this seemed to me to be a way around some of the limitations and is much simpler to setup, for example I can define and store the SQL server name and the SQL server credentials in the Automation account itself, which is much better if I ever need to change the SQL server or it's login details, I also don't need to create or manage credentials across the individual databases, what I couldn't find though was anyway of targeting all databases within an elastic database pool (or even better target all databases within a pool excluding a single database) now Azure Automation relies on runbooks the same as elastic jobs does so I guess this comes down to if it is possible to define the elastic database pool as the target within the PowerShell script / runbook?
here is my working script using an Automation account to rebuild the indexes on schedule, using the database stored procedure AzureSQLMaintenance.
$AzureSQLServerName = Get-AutomationVariable -Name "SqlServer"
$AzureSQLServerString = $AzureSQLServerName + ".database.windows.net"
$Cred = Get-AutomationPSCredential -Name "Credential1"
$AzureSQLDatabaseName1 = "my_database_name1"
$AzureSQLDatabaseName2 = "my_database_name2"
$AzureSQLDatabaseName3 = "my_database_name3"
$AzureSQLDatabaseName4 = "my_database_name4"
$AzureSQLDatabaseName5 = "my_database_name5"
$AzureSQLDatabaseName6 = "my_database_name6"
Invoke-Sqlcmd -ServerInstance $AzureSQLServerString -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName1 -Query "exec [dbo].[AzureSQLMaintenance] @Operation='all' ,@mode='smart',@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60
Invoke-Sqlcmd -ServerInstance $AzureSQLServerString -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName2 -Query "exec [dbo].[AzureSQLMaintenance] @Operation='all' ,@mode='smart',@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60
Invoke-Sqlcmd -ServerInstance $AzureSQLServerString -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName3 -Query "exec [dbo].[AzureSQLMaintenance] @Operation='all' ,@mode='smart',@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60
Invoke-Sqlcmd -ServerInstance $AzureSQLServerString -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName4 -Query "exec [dbo].[AzureSQLMaintenance] @Operation='all' ,@mode='smart',@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60
Invoke-Sqlcmd -ServerInstance $AzureSQLServerString -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName5 -Query "exec [dbo].[AzureSQLMaintenance] @Operation='all' ,@mode='smart',@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60
Invoke-Sqlcmd -ServerInstance $AzureSQLServerString -Username $Cred.UserName -Password $Cred.GetNetworkCredential().Password -Database $AzureSQLDatabaseName6 -Query "exec [dbo].[AzureSQLMaintenance] @Operation='all' ,@mode='smart',@LogToTable=1" -QueryTimeout 65535 -ConnectionTimeout 60
does anyone know if it is possible to target the elastic database pool , excluding a single database within that pool in PowerShell?
I'll also need this for other tasks, such as setting column data classification and sensitivity labels, data collection and reporting etc so being able to target an elastic group would really help
Many thanks, Simon