Best way to query a SSAS tabular via powershell

1k Views Asked by At

I'm very new about SSAS and MS in general. I want to ask you which is the best way to run a simple select query against a SSAS tabular model via powershell.

I have seen the Invoke-ASCmd using the TMSL, but i've not found an example for a simple select statement, so i m not sure is the right way.

Thanks

Giancarlo

1

There are 1 best solutions below

0
On

Example run DAX statment equvivalent for "select * from table":

$connectionString = “Provider=MSOLAP;Data Source=.;Initial Catalog=Mydatabase;”
$query = “evaluate TABLE”

$filename = “tofile.csv”
 
$connection = New-Object -TypeName System.Data.OleDb.OleDbConnection

$connection.ConnectionString = $connectionString
$command = $connection.CreateCommand()
$command.CommandText = $query
$adapter = New-Object -TypeName System.Data.OleDb.OleDbDataAdapter $command
$dataset = New-Object -TypeName System.Data.DataSet
$adapter.Fill($dataset)

$dataset.Tables[0] | export-csv $filename -notypeinformation
  
$connection.Close()