Microsoft Docs

Scripting in Analysis Services

Use scripting to automate the creation, modification, and deployment of objects in SQL Server Analysis Services (SSAS). The primary scripting language is XMLA (XML for Analysis) which can be executed via SQL Server Management Studio (SSMS), PowerShell, or programmatically through the ADOMD.NET library.

Prerequisites

Common Scripting Scenarios

  1. Backup a database
  2. Process cubes and dimensions
  3. Deploy a model from a BISM Tabular project
  4. Script out objects for version control

Example: Backing up an SSAS Database

<?xml version="1.0" encoding="UTF-8"?>
<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
    <Backup xmlns="urn:schemas-microsoft-com:xml-analysis">
        <Object>
            <DatabaseID>AdventureWorksDW2019</DatabaseID>
        </Object>
        <File>C:\Backups\AdventureWorksDW2019.abf</File>
        <AllowOverwrite>true</AllowOverwrite>
    </Backup>
</Batch>

Run the script in SSMS: New Query > XMLA → paste the XML and execute.

Example: Processing a Cube

<Process xmlns="urn:schemas-microsoft-com:xml-analysis">
    <Object>
        <DatabaseID>AdventureWorksDW2019</DatabaseID>
        <CubeID>Adventure Works</CubeID>
    </Object>
    <Type>ProcessFull</Type>
    <ObjectExpansion>ExpandObject</ObjectExpansion>
</Process>

PowerShell Automation

# Requires the SqlServer module
Import-Module SqlServer
$xmla = Get-Content .\BackupAdventureWorks.xml
Invoke-ASCmd -DatabaseServer "localhost" -InputFile $xmla

Related Topics