2

Tried to connect to the tabular model and create a partition on an analysis services tabular model. The piece of code mentioned below.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular")
#Here, the variables are declared to be used
$ServerName = "<analysis SERVICE URI>"
$DatabaseName = "ProductReportingModelPartitionTest"

$Server = New-Object Microsoft.AnalysisServices.Tabular.Server
#Connecting to the Tabular Server
$Server.Connect("$ServerName")
#Declaring which Tabular database to connect to
$DatabaseName = $Server.Databases["$DatabaseName"]
$Model = $DatabaseName.Model

function Add-NewPartition ($_table,$_originalPartition) {
   #Find the partition by name in the model
   $PartitionExists = $_table.Partitions.Find("DevPartition")
   echo($PartitionExists | Format-Table)
   #Check if the partition was already created, if not exit. 
   if (!$PartitionExists)
   {
        #Clone the reference partition that has placeholder 1=2
        $NewPartition = $_originalPartition.Clone()
        
        #Give a name to the new partition, something that can be found
        $NewPartition.Name = "deve0osl"
        #Add the new partition
        $_table.Partitions.Add( $NewPartition )
        
        #Call the refresh data process method to refresh the data of the new partition 
        $NewPartition.RequestRefresh("Data") 
   }
}



$Table = $Model.Tables["Online Stock - Seasons"]


$OriginalPartition = $Table.Partitions[0]

Add-NewPartition $Table $OriginalPartition

Up until $NewPartition its worning. But $_table.Partitions.Add( $NewPartition ) doesnt work. Please help thanks in advance.

AmilaMGunawardana
  • 1,604
  • 2
  • 13
  • 32

1 Answers1

2

Just found out the solution. Forgot to include $Model.SaveChanges()

AmilaMGunawardana
  • 1,604
  • 2
  • 13
  • 32