THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Jorg Klein

Microsoft Data & Analytics consultant and Microsoft Data Platform MVP from the Netherlands

Process Azure Analysis Services databases from Azure Automation

In my last blog post I showed how to trigger Azure Data Factory (ADF) pipelines from Azure Automation. I also mentioned the option to process an Azure Analysis Services cube from Azure Automation. For example right after your ADF data processing finishes, which will probably be a common use case. In this blog post I show you how you can use the Analysis Services PowerShell provider, also known as SQLASCDMLETS, from Azure Automation.

Create custom SQLASCMDLETS module
The SQLASCDMLETS are not (yet) available in the PowerShell Gallery so unfortunately it’s not possible to import the cmdlets straight into Automation like I did with the ADF cmdlets in my previous blog post. Instead we have to create our own module which will contain the SQLASCMDLETS and its dependencies.
The required files come with SQL Server Management Studio (SSMS) which you can download and install for free. It’s important to note you need the latest version (140) of the SQLASCDMLETS which is shipped with the latest Release Candidate of SSMS. Download and install it.

If you try to use the previous version of the SQLASCDMLETS (130) you will get an error in Automation because it tries to authenticate with a claims token while only windows authentication is supported by the 130 version of SQLASCDMLETS: “The value 'ClaimsToken' is not supported for the connection string property”.

After installing SSMS you should now be able to see the following directory: C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\SQLASCMDLETS

Copy the SQLASCMDLETS folder to a temporary location, for example C:\SQLASCMDLETS.
You will need the following files:

  • Microsoft.AnalysisServices.PowerShell.Cmdlets.dll
  • SQLASCMDLETS.PSD1

We also need the libraries SQLASCMDLETS depends on. Search your computer for the following files and copy paste them to the C:\SQLASCMDLETS folder. Make sure you copy them from a folder that has “140” in the path so you are sure you have the correct version.

  • Microsoft.AnalysisServices.Core.dll
  • Microsoft.AnalysisServices.Tabular.dll
  • Microsoft.AnalysisServices.dll

Now zip the entire folder, make sure the name is “SQLASCMDLETS.zip”.


Import custom SQLASCMDLETS module to Azure Automation
Navigate to your Azure Automation account in the Azure portal.

Click Assets:
clip_image002

Click Modules:
clip_image004

Click Add a module to import a custom module:
clip_image006

Now upload the SQLASCMDLETS.zip file:
clip_image008

The zip file will be extracted:
clip_image010

Wait until the extraction finished and the status changes to Available. Click on the module name:
clip_image012

You now see the available activities including the one we will use to process the Azure Analysis Services Database:
clip_image014


Create Azure Automation Credential
Now we need to create a Credential to be able to automatically login and run our PowerShell script unattended from Azure Automation.

Navigate to Assets again and then click Credentials:
clip_image016

Click “Add a credential” and enter an organization account that has permissions to process your Azure Analysis Services database. Make sure you enter the User Principal Name (UPN) and not a Windows AD account. It is often the email address and may look like jorgk@yourorganizationalaccountname.com. Give the new Credential a name, I chose “adpo-auto-cred”. It will be referenced in the PowerShell script below.
clip_image018


Create Automation Runbook
You can use the simple PowerShell script below to process your Azure Analysis Services database from Azure Automation. It will use the “adpo-auto-cred” credential to authenticate and will process your database using the Invoke-ProcessASDatabase SQLASCMDLETS function.
Replace “dbname” with your database name and “server” with your server, e.g. asazure://westeurope.asazure.windows.net/yourserver and you are good to go.

Copy/paste the script below to a Windows PowerShell Script (.ps1) file and name it “ProcessASDatabase.ps1”.


$AzureCred = Get-AutomationPSCredential -Name "adpo-auto-cred"

 

Add-AzureRmAccount -Credential $AzureCred | Out-Null

 

Invoke-ProcessASDatabase -databasename "dbname" -server "server" -RefreshType "Full" -Credential $AzureCred 


Navigate to your Azure Automation account in the Azure Portal and click “Runbooks”:
clip_image020

Click “Add a runbook”:
clip_image022

Click “Import an existing workbook” and select the ProcessASDatabase.ps1 file to import the PowerShell script as Runbook:
clip_image024

Runbook ProcessASDatabase is created. Click it to open it:
clip_image026

A Runbook must be published before you are able to start or schedule it. Click Edit:
clip_image027

Before publishing, test the Runbook first. Click on the “Test pane” button and then click Start:
clip_image029

The script executed successfully:
clip_image031

Connect to your Azure AS sever with SSMS and check the database properties to be sure processing succeeded:
clip_image033

Now publish the Runbook:
clip_image035

That’s it, you now have an Azure Automation Runbook that you can schedule, monitor and integrate with your other data platform related tasks!

Published Friday, January 27, 2017 2:32 PM by jorg

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Ryan said:

I've tried installing both the 16.5.3 and the 17RC1 versions of SSMS and while I get the "C:\Program Files (x86)\Microsoft SQL Server\140\Tools" directory, there is no "PowerShell" directory

January 31, 2017 5:41 PM
 

jorg said:

Hi Ryan,

If you search your computer for file "SQLASCMDLETS.PSD1", do you find it in some folder with "140" in the path? If you do, you can take the files from there.

February 1, 2017 4:20 AM
 

Ryan said:

Ahh...oops... I was looking in "Program Files" instead of "Program Files (x86)", sorry!

February 1, 2017 2:36 PM
 

Jeff said:

This is great. Detailed and easy to follow. Thanks!

February 1, 2017 3:58 PM
 

JC said:

I try to import the module but I get his "Activity Extraction Failed" message:

Error extracting the activities from module SQLASCMDLETS. Extraction failed with the following error: Orchestrator.Shared.AsyncModuleImport.ModuleImportException: While importing the module, an error occurred while processing the module content. Internal error message: Could not load file or assembly 'Microsoft.AnalysisServices.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified..

Any idea why?

February 1, 2017 5:25 PM
 

JC said:

Never mind, I solved that problem. Still struggling getting the cmdlet to work. something to do with a ConnectionException.

February 2, 2017 1:07 AM
 

Bhavin said:

I installed new SSMS from above mentioned link but cant find 140 directory under Microsoft SQL Server in Program Files(x86) as well as Program Files.

February 2, 2017 1:23 AM
 

JC said:

I wanted to say thanks Jorg. I got this to work great.  The first problem I had was getting the right files for the module.  With the various versions of SSMS I had running I was including files from different versions.  I narrowed that problem and all the files I used had the same date. Once I got through that my issue was entirely in a typo of mine.  Anyway, Thanks!

February 2, 2017 11:45 AM
 

RB said:

This thing works only problem i am facing is script once executed in Azure is not ending model gets refreshed but script is still on going. Can anyone help me for this?

February 3, 2017 2:18 AM
 

Pawel said:

Great article, works like a charm! the only thing is that location of the DLLs changed to C:\Windows\Microsoft.NET\assembly\GAC_MSIL

Thanks!

February 10, 2017 1:21 AM
 

Johann said:

I had the same problem as JC, I solved it by installed the latest SQL Server Data Tools: https://docs.microsoft.com/en-us/sql/ssdt/sql-server-data-tools-ssdt-release-candidate

The assemblies were then available from the GAC: C:\Windows\Microsoft.NET\assembly\GAC_MSIL

February 20, 2017 8:46 AM
 

Aravind said:

I could get the dll's from C:\Program Files (x86)\Microsoft SQL Server\140\Tools\PowerShell\Modules\SQLASCMDLETS and C:\Windows\Microsoft.NET\assembly\GAC_MSIL

But strange part is when i add module to Azure automation, Extracting activities fail with below error.

Error extracting the activities from module SQLASCMDLETS. Extraction failed with the following error: Orchestrator.Shared.AsyncModuleImport.ModuleImportException:

While importing the module, an error occurred while processing the module content. Internal error message:

Could not load file or assembly 'Microsoft.AnalysisServices.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified..

Can any one help?

March 1, 2017 6:07 PM
 

Aravind said:

I got it fixed with other set of assemblies available in  C:\Windows\Microsoft.NET\assembly\GAC_MSIL . Thx.

March 1, 2017 6:45 PM

Leave a Comment

(required) 
(required) 
Submit

About jorg

Jorg Klein, Microsoft Data & Analytics consultant from the Netherlands.
Privacy Statement