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!!!
see https://learn.microsoft.com/en-us/azure/sql-database/scripts/sql-database-monitor-and-scale-pool-powershell
This PowerShell script example monitors the performance metrics of an elastic pool, scales it to a higher performance level, and creates an alert rule on one of the performance metrics.
PS C:\>Set-AzSqlElasticPool 
    -ResourceGroupName "ResourceGroup01" 
    -ServerName "Server01" 
    -ElasticPoolName "ElasticPool01" 
    -Dtu 1000 
    -DatabaseDtuMax 100 
    -DatabaseDtuMin 20
ResourceId        : /subscriptions/00000000-0000-0000-0000-000000000001/resourceGroups/resourcegroup01/providers/Microsoft.Sql/servers/Server01/elasticPools/ElasticPool01
ResourceGroupName : ResourceGroup01
ServerName        : Server01
ElasticPoolName   : ElasticPool01
Location          : Central US
CreationDate      : 8/26/2015 10:00:17 PM
State             : Ready
Edition           : Standard
Dtu               : 200
DatabaseDtuMax    : 100
DatabaseDtuMin    : 20
StorageMB         : 204800
Tags              :
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With