This adds the Adventure Works DW 2008R2 cube section (in particular, the Internet client measurement 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 will need to change the variables at the top and the link to the assembly Microsoft.AnalysisServices.dll
, but, in addition, it will work peach.
The trick is to call the Update()
object, and then the entire database.
If you want to process a new partition, you can do this with the following line up to $srv.Disconnect
:
$srv.Databases[$catalog].Cubes[$cube].MeasureGroups[$measure_group].Partitions[$new_partition].Process()
You can learn more about Analysis Management Objects (AMOs) here .
Eric
source share