Azure Automation – How to get your 1st Runbook working properly… « The SQL Dude!

      Comments Off on Azure Automation – How to get your 1st Runbook working properly… « The SQL Dude!


Azure Automation – How to get your 1st Runbook working properly…

Posted by Sudarshan Narasimhan on September 9, 2016

Been participating in about with Azure Automation this previous month and had a need to Up-scale & Down-scale Azure SQL Databases tiers in an automatic method. I’m chatting Azure SQL DB (DBaaS) and not SQL Server on Azure (IaaS). To get this automation, we had been employing the Azure Runbook Automation PowerShell workflow.

Generally, we desired to up-scale the databases tier from Premium P1 to P2 in the morning and down-scale it again down to P1 in the night time. To help save expenses you know 😉
There is a large amount of facts on the WWW displaying diverse techniques just one can generate a PS automation workflow. This article is to present you just 1 way that I was equipped to get it to perform.

  1. Login to your Azure Subscription and go to the Source Group that contains the SQL Database you will need to perform with.
  2. Create a new Automation Account
  3. Considering the fact that I was trying to automate just our Cloud things in Azure (SQL DB), I finished up picking the authentication strategy for the Automation account as “Azure Run As Account”
    Notice: you can also use an Azure Advertisement Account depending on your organization’s architecture
  4. As soon as the automation account has been setup, open up it is blade in the Azure Portal and bought to Runbooks. You will recognize that there are now 3-4 tutorial runbooks existing there by default.
  5. Increase a Runbook -> Make a new Runbook. Give it some meaningful name for e.g. ResizeSQLDatabase
  6. For the runbook variety, I chose PowerShell workflow. (You can use the Graphical workflow as well).
  7. You must now see a new PS workflow window with the workflow identify that you specified. Just like a regular PS workflow, you can define enter parameters in the param () block.
See also  Some of History’s Best-Hidden Marketing Stunts – and Some of the Worst. – Paige Briscoe


The beneath stage is vital. For Azure automation to operate, it needs to use some sort of qualifications to conduct your automation get the job done. In my scenario up-scale & down-scale databases tiers on a timetable. Duplicate & paste the down below code section correct immediately after the param block in the workflow

# Get the link "AzureRunAsConnection"

$connectionName = "AzureRunAsConnection"
$servicePrincipalConnection=Get-AutomationConnection -Title $connectionName

    "Logging in to Azure..."
    Increase-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint


    if (!$servicePrincipalConnection)
        $ErrorMessage = "Relationship $connectionName not observed."
        throw $ErrorMessage
        Create-Mistake -Message $_.Exception
        toss $_.Exception

What the earlier mentioned code is undertaking is basically using the constructed-in automation account referred to as “AzureRunAsConnection” and it is qualifications to run the PS workflow.

Now, coming to the genuine SQL DB scaling, you can use the beneath cmdlet to do that
Set-AzureRMSqlDatabase -DatabaseName $DatabaseName -ResourceGroupName $ResourceGroupName -ServerName $ServerName -Edition $NewEdition -RequestedServiceObjectiveName $NewPricingTier

Each of the $variables in the above line are input parameters to my runbook. $NewPricingTier is the a person that controls the SQL database tier & DTU’s
You can uncover extra info about the parameters values here -> articles/sql-database-services-tiers/?rnd=1

The moment completed, conserve the runbook and produce task schedules for the new runbook with the acceptable enter parameters and enable Azure Automation do the do the job for you! 😀

Just a brief article to aid any one out there with their first Azure Automation runbook.

This entry was posted on September 9, 2016 at 3:28 PMand is filed under Azure, Code Samples, PowerShell.
Tagged: automobile scale, Azure Automation, Credential, Powershell workflow, SQL Databases tiers. You can comply with any responses to this entry by the RSS 2. feed.

You can depart a responseor trackback from your personal internet site.


Resource link