Puneet Tripathi
Puneet Tripathi

Reputation: 71

Creating SSAS 2008 cube partitions using Powershell?

How can we create SSAS 2008 cube partitions using Powershell?

Upvotes: 7

Views: 1956

Answers (3)

Abdeloihab Bourassi
Abdeloihab Bourassi

Reputation: 975

you can use :

Microsoft.AnalysisServices.Deployment [ASdatabasefile] 
{[/s[:logfile]] | [/a] | [[/o[:output_script_file]] [/d]]}

to deploy your cube AS with powershell.

Upvotes: -2

Eric
Eric

Reputation: 95093

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.

Upvotes: 6

Brandon
Brandon

Reputation: 411

Check out this: PowerSSAS

It doesn't have explicit add partition support, so you'll probably have to craft an XMLA snippet to do the add partition and then use PowerSSAS to push it to the SSAS server.

Upvotes: 1

Related Questions