As titled, I am trying to automatically scale my Azure databases. I have found a powershell workflow script for a single database, which works perfectly. I was wondering if it is possible to automatically scale my elastic pool. I have tried to rewrite the script, but failed many times.
Here is the script below:
workflow Set-AzureSqlDatabaseEdition
{
param
(
# Name of the Azure SQL Database server (Ex: bzb98er9bp)
[parameter(Mandatory=$true)]
[string] $SqlServerName,
# Target Azure SQL Elastic Pool
[parameter(Mandatory=$true)]
[string] $ElasticPoolName,
# Desired Azure SQL Elastic Pool edition {Basic, Standard, Premium}
[parameter(Mandatory=$true)]
[string] $Edition,
# Desired DTU
[parameter(Mandatory=$true)]
[string] $DTU,
# DatabaseDtuMin
[parameter(Mandatory=$true)]
[string] $DatabaseDtuMin,
# DatabaseDtuMax
[parameter(Mandatory=$true)]
[string] $DatabaseDtuMax,
# Credentials for $SqlServerName stored as an Azure Automation credential asset
# When using in the Azure Automation UI, please enter the name of the credential asset for the "Credential" parameter
[parameter(Mandatory=$true)]
[PSCredential] $Credential
)
inlinescript
{
Write-Output "Begin vertical scaling script..."
# Establish credentials for Azure SQL Database server
$Servercredential = new-object System.Management.Automation.PSCredential($Using:Credential.UserName, (($Using:Credential).GetNetworkCredential().Password | ConvertTo-SecureString -asPlainText -Force))
# Create connection context for Azure SQL Database server
$CTX = New-AzureSqlDatabaseServerContext -ManageUrl “https://$Using:SqlServerName.database.windows.net” -Credential $ServerCredential
# Get Azure Elastic Pool context
$EP = Get-AzureRmSqlElasticPool $CTX ElasticPoolName $Using:ElasticPoolName
# Specify the specific performance level for the target $DatabaseName
$DTU = Get-AzureRmSqlElasticPool $CTX ElasticPoolName $Using:DTU
# Set the new edition/performance level
Set-AzureRmSqlElasticPool $CTX ElasticPoolName $DTU –ServiceObjective $DTU –Edition $Using:Edition -Force
# Output final status message
Write-Output "Scaled the performance level of $Using:DatabaseName to $Using:Edition - $Using:PerfLevel"
Write-Output "Completed vertical scale"
}
}
I hope someone can point me a right direction to do that if it is possible.
Many Thanks!!!