Hi All
In today's blog post, I'll delve into the intricacies of processing SSAS tabular models using PowerShell. PowerShell, renowned for its robustness with a consistent syntax, object-oriented pipeline, a wealth of cmdlets, and scripting prowess, stands out as an efficient tool for system administration. Its vibrant community, cross-platform compatibility, and seamless integration with Microsoft products further underscore its versatility.
However, please note that this blog won't guide you through the basics of getting started with PowerShell. I plan to cover that in our next blog post, so stay tuned for that valuable information.
First you required to install SqlServer powershell module. Ener following code in Powershell cmd prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Module -Name SqlServer -Force -AllowClobber |
In this post im going to give two examples
- Processing a model
- Add and process a new SSAS Tabular partition
Example 1 Processing a model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Assembly | |
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") >$NULL | |
# Connect to Tabular SSAS | |
$srv = New-Object Microsoft.AnalysisServices.Server | |
$srv.connect("localhost\TABULAR") | |
# Point to a specific Database | |
$db = $srv.Databases.FindByName("DatabaseName"); | |
# Process the entire database | |
# Options: ProcessFull, ProcessData, ProcessDefault | |
$db.Process("ProcessFull") | |
# Disconnect from Analysis Services | |
Disconnect-AnalysisServer -Server $server |
Example 2 Add and process a new SSAS Tabular partition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Assembly | |
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") >$NULL | |
# Connect to Tabular SSAS | |
$srv = New-Object Microsoft.AnalysisServices.Server | |
$srv.connect("localhost\TABULAR") | |
# Point to a specific Database | |
$db = $srv.Databases.FindByName("DatabaseName"); | |
# Store the Data Source View (*MUST* be Sandbox) | |
$dsv = $db.DataSourceViews.FindByName("Sandbox"); | |
# Select a specific Model | |
$c = $db.Cubes.FindByName("ModelName"); | |
# Select a specific Table | |
$mg = $c.MeasureGroups.FindByName("TableName"); | |
# Add new partition and process it | |
$p = $mg.Partitions.Add("NewPartitionName"); | |
$p.Source = New-Object Microsoft.AnalysisServices.QueryBinding($dsv.DataSourceID, "SELECT * FROM [Table] WHERE [PartitionColumn] = 1234"); | |
$p.StorageMode = 'InMemory' | |
$p.Update('ExpandFull') | |
$p.Process('ProcessFull') | |
$srv.Disconnect() |