Azure Automation Use Cases

Using Azure Automation to process Azure Analysis Services Cubes

Azure Automation is a new service in Azure that allows you to automate your Azure management tasks and to orchestrate actions across external systems from right within Azure. It is built on PowerShell Workflow, so you can take advantage of the language’s many features. If you have not yet signed up for Azure Automation, sign up for our free preview here. You can also learn more about Azure Automation here

Before starting we need to create an Azure Automation account using the Azure Portal

In this post I will show you a very simple, yet effective way of processing, maintaining and managing your Azure Analysis Services cubes.

Here is the Powershell code to upgrade the Azure Analysis Services Server to S2 pricing tier

# PowerShell code 
# Don't continue in case of an error
#$ErrorActionPreference = "Stop"
# Connect to a connection to get TenantId and SubscriptionId
$Connection = Get-AutomationConnection -Name "AzureRunAsConnection"
$TenantId = $Connection.TenantId
$SubscriptionId = $Connection.SubscriptionId
# Get the service principal credentials connected to the automation account. 
$null = $SPCredential = Get-AutomationPSCredential -Name "azure automation credentials here"
# Login to Azure ($null is to prevent output, since Out-Null doesn't work in Azure)
Write-Output "Login to Azure using automation account 'azure automation credentials here'."
$null = Login-AzureRmAccount -TenantId $TenantId -SubscriptionId $SubscriptionId -Credential $SPCredential
# Select the correct subscription
Write-Output "Selecting subscription '$($SubscriptionId)'."
$null = Select-AzureRmSubscription -SubscriptionID $SubscriptionId
# Get variable values
$ResourceGroupName = 'resource group name' # Get-AutomationVariable -Name 
$AnalysisServerName = 'azure analysis services server name' # Get-AutomationVariable -Name 
# Get old status (for testing/logging purpose only)
$OldAsSetting = Get-AzureRmAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
# changing tier
Write-Output "Upgrade $($AnalysisServerName) to S2. Current tier: $($OldAsSetting.Sku.Name)"
Set-AzureRmAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName -Sku "S2"
Write-Output "Done"

$Currenttier = Get-AzureRmAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName

If ($Currenttier.Sku.Name -eq "S2") {
  Write-Output "Done"
  Write-Output "Current tier: $($Currenttier.Sku.Name)"
  }  Else {

   Write-Output "Not Done"

# Get new status (for testing/logging purpose only)
$NewAsSetting = Get-AzureRmAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName
Write-Output "New tier: $($NewAsSetting.Sku.Name)"

Likewise, if you need to downgrade you can just change the above to code to the following

# changing tier
Write-Output "Downgrade $($AnalysisServerName) to S1. Current tier: $($OldAsSetting.Sku.Name)"
Set-AzureRmAnalysisServicesServer -ResourceGroupName $ResourceGroupName -Name $AnalysisServerName -Sku "S1"
Write-Output "Done"

Here is the code to process analysis services cubes

# Get the values stored in the Assets
$TenantId = "your tenant id"
$Credential = Get-AutomationPSCredential -Name 'credential name'
$Server = "asazure://"
$DatabaseName = "cube name"
$RolloutEnvironment = ""
# Log in to Azure Analysis Services using the Azure AD Service Principal
Add-AzureAnalysisServicesAccount -Credential $Credential -ServicePrincipal -TenantId $TenantId -RolloutEnvironment $RolloutEnvironment
# Perform a Process Full on the Azure Analysis Services database
Invoke-ProcessASDatabase -Server $Server -DatabaseName $DatabaseName -RefreshType "Full"

Follow My Blog

Get new content delivered directly to your inbox.

%d bloggers like this: