Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating SSAS 2008 cube partitions using Powershell?

How can we create SSAS 2008 cube partitions using Powershell?

like image 589
Puneet Tripathi Avatar asked Dec 22 '11 16:12

Puneet Tripathi


People also ask

How do you partition a cube?

To start creating partitions, we need to go to the Partitions tab in the cube editor. There is a default partition that will contain all the data for the measure group. I already created an aggregation design and assigned it to the partition.

Can we partition the Measuregroup in SSAS?

Partitions are used by Microsoft SQL Server SQL Server Analysis Services to manage and store data and aggregations for a measure group in a cube. Every measure group has at least one partition; this partition is created when the measure group is defined.


1 Answers

This adds a partition to the Adventure Works DW 2008R2 cube (specifically the Internet Customers measure group in the Adventure Works cube):

$server_name = "localhost"
$catalog = "Adventure Works DW 2008R2"
$cube = "Adventure Works"
$measure_group = "Fact Internet Sales"
$old_partition = "Customers_2004"
$new_partition = "Customers_2009"
$old_text = "'2008"
$new_text = "'2009"

[Reflection.Assembly]::LoadFile("C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.AnalysisServices.DLL")
$srv = new-object Microsoft.AnalysisServices.Server
$srv.Connect("Data Source=" + $server_name)
$new_part = $srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$old_partition].Clone()
$new_part.ID = $new_partition
$new_part.Name = $new_partition
$new_part.Source.QueryDefinition = $new_part.Source.QueryDefinition.Replace($old_text, $new_text)
$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions.Add($new_part)
$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$new_partition].Update()
$srv.Databases[$catalog].Update()
$srv.Disconnect()

You'll have to change variables up top, and the reference to the Microsoft.AnalysisServices.dll assembly, but other than that, this will work peachy keen.

The trick is to call Update() on the object changed and then on the whole database itself.

If you'd like to process the new partition, as well, you can do that with the following line before $srv.Disconnect:

$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$new_partition].Process()

You can learn more about Analysis Management Objects (AMO) here.

like image 140
Eric Avatar answered Oct 01 '22 02:10

Eric