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
- SQL Server 2019 or later with Analysis Services installed.
- SQL Server Management Studio (SSMS) 18.0 or newer.
- Basic knowledge of XML and MDX/DAX.
Common Scripting Scenarios
- Backup a database
- Process cubes and dimensions
- Deploy a model from a BISM Tabular project
- 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