1

Summary: I am using Invoke-ASCmd –InputFile "$templateLocation" -Server $serverName on PowerShell to deploy a model/table to Azure Analysis Services (AAS) server. The problem is that I get the error "Invoke-ASCmd : Index was outside the bounds of the array".

Details: I already have a database deployed to AAS server with OAuth and it has only one table. I want to add another table using a Json file template. I have done the same procedure using an on-premises Analysis Services server with Windows Authentication and a model created with SQL Server Tables - and it worked perfectly.

Now the difference is that my AAS server requires OAuth authentication. Moreover, the model was created with tables that are txt files in a Azure Data Lake. Bottom line, I wanted to know how I can add a table to the existing AAS model without having to use credentials automation, runbooks, etc.

Here is my PowerShell script.

###########################
#Location of Templates
###########################
$masterFolderLocation = "C:\Templates\"
$templateLocation = $masterFolderLocation + 'MyModel.json' # xmla/json with one table to be added to model
Write-Output "Template location:" $templateLocation

###########################
#Variables
###########################
$databaseName = "MyDatabase" # This database already exists in the AAS server
$serverName = "asazure://aspaaseastus2.asazure.windows.net/myserver"; # Azure Analysis Services Server

###########################
#Server Connection
###########################
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular")
$svr = New-Object Microsoft.AnalysisServices.Tabular.Server
$svr.Connect($serverName)

###########################
#Count number of databases
###########################
$database = $svr.databases[1]
Write-Host "Number of Databases in the server:" $svr.databases[1].model.tables.count


###########################
#Refresh Model
###########################
Write-Host "Refreshing model..."
$database = $svr.Databases[$databaseName]
$model = $database.Model
$model.RequestRefresh([Microsoft.AnalysisServices.Tabular.RefreshType]::Full)

###########################
#Save Changes
###########################
Write-Host "Saving model..."
$database.Model.SaveChanges()

###########################
#Deploy
###########################
Invoke-ASCmd –InputFile "$templateLocation" -Server $serverName

Here is the error I get:

Invoke-ASCmd : Index was outside the bounds of the array.
At C:\Users\StackOverflow.ps1:45 char:1
+ Invoke-ASCmd –InputFile "$templateTabular" -Server $serverName
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-ASCmd], IndexOutOfRangeException
    + FullyQualifiedErrorId : System.IndexOutOfRangeException,Microsoft.AnalysisServices.PowerShell.Cmdlets.ExecuteScriptCommand

Here is my Json template (meant to be used to add only one table to already existing database/model)

{
  "create": {
    "parentObject": {
      "database": "MyDatabase"
    },
    "table": {
      "name": "Department",
      "columns": [
        {
          "name": "DepartmentId",
          "dataType": "int64",
          "isHidden": true,
          "sourceColumn": "DepartmentId",
          "summarizeBy": "none"
        },
        {
          "name": "Department",
          "dataType": "string",
          "sourceColumn": "Department"
        }
      ],
      "partitions": [
        {
          "name": "Partition",
          "dataView": "full",
          "source": {
            "type": "m",
            "expression": [
              "let",
              "    Source=GetFileList(),",
              "    #\"Department txt\" = Source{[Name=\"Department.txt\"]}[Content],",
              "    #\"Imported CSV\" = Csv.Document(#\"Department txt\",[Delimiter=\"|\", Columns=5, Encoding=65001, QuoteStyle=QuoteStyle.None]),",
              "    #\"Promoted Headers\" = Table.PromoteHeaders(#\"Imported CSV\", [PromoteAllScalars=true]),",
              "    #\"Changed Type\" = Table.TransformColumnTypes(#\"Promoted Headers\",{{\"DepartmentId\", Int64.Type}, {\"Department\", type text})",
              "in",
              "    #\"Changed Type\""
            ]
          }
        }
      ]
    }
  }
}



user12525899
  • 133
  • 1
  • 10

0 Answers0