Skip to content

Instantly share code, notes, and snippets.

@yorek
Created April 8, 2015 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yorek/77eca81a1ab4e0f51dea to your computer and use it in GitHub Desktop.
Save yorek/77eca81a1ab4e0f51dea to your computer and use it in GitHub Desktop.
Powershell script to add and process a new SSAS Multidimensional partition (mimicking subpartitions usage)
# Load Assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") >$NULL
# Connect to Tabular SSAS
$srv = New-Object Microsoft.AnalysisServices.Server
$srv.connect("localhost")
# Point to a specific Database
$db = $srv.Databases.FindByName("MyDatabase");
# Store the Data Source View (*MUST* be Sandbox)
$dsv = $db.DataSourceViews.FindByName("MyDataSourceView");
# Select a specific Cube
$c = $db.Cubes.FindByName("MyCube");
# Select a specific MeasureGroup
$mg = $c.MeasureGroups.FindByName("MyMeasureGroup");
# Set partition info
$partition_base_name = "Partition"
$partition_c1 = 2013, 2014, 2015
$partition_c2 = 0001, 0002, 0003, 0004, 0005
# Create partitions
foreach($c1 in $partition_c1)
{
foreach($c2 in $partition_c2)
{
$partition_name = "$partition_base_name-$c1-$c2"
Write-Host $partition_name
$p = $mg.Partitions.GetByName($partition_name)
if ($p -ne $null)
{
$p.Drop()
}
$p = $mg.Partitions.Add($partition_name)
$p.StorageMode = "Molap";
$qb = New-Object Microsoft.AnalysisServices.QueryBinding
$qb.DataSourceID = $dsv.DataSourceID
$qb.QueryDefinition = "SELECT * FROM <source> WHERE partition_column = " + $c1 + "0" + $c2
$p.Source = $qb
$p.Slice = "(<dim1>.&[$c1], <dim2>.&[$c2])"
$p.Update()
}
}
$srv.Disconnect()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment