Unexpected token 'UpdateOptions.ExpandFull'

Viewed 319

Based on https://docs.microsoft.com/en-us/bi-reference/tom/add-a-data-source-to-tabular-model-analysis-services-amo-tom

i am trying to update the Database connectionstring changes:

Import-Module SqlServer

$newConnectionString = "Connection Timeout=60;User Id=SOME_NEW_ID;Data Source=10.10.19.10;Persist Security Info=True;Session Character Set=UTF8"

 $svr = new-Object Microsoft.AnalysisServices.Tabular.Server
$svr.Connect("server1.domain.com")

$svr.databases[1].model.datasources[0].ConnectionString = $newConnectionString
$svr.Databases[1].model.datasources[0].Update(UpdateOptions.ExpandFull)

But i am getting errors:

Unexpected token 'UpdateOptions.ExpandFull' in expression or statement.

if i do regular Update():

$svr.Databases[1].model.datasources[0].Update()

i get this:

Method invocation failed because [Microsoft.AnalysisServices.Tabular.ProviderDataSource] does not contain a method named 'Update'

and if i try SaveChanges():

$svr.Databases[1].Model.SaveChanges()

I get this error:

The following exception occurred while retrieving member "SaveChanges": "Encountered an invalid type for a default value."

if i try just ExpandFull

$svr.Databases[1].model.datasources[0].Update(ExpandFull)

i get

Unexpected token 'ExpandFull' in expression or statement.

2 Answers

The error is the way that you specify the enum for the update.

You are working directly with .NET types and you have to understand / know where a given enum belongs. In this case the UpdateOptions lives in the Microsoft.AnalysisServices namespace

Updated

Import-Module SqlServer

$newConnectionString = "Connection Timeout=60;User Id=SOME_NEW_ID;Data Source=10.10.19.10;Persist Security Info=True;Session Character Set=UTF8"

$svr = new-Object Microsoft.AnalysisServices.Tabular.Server
$svr.Connect("server1.domain.com")

$svr.databases[1].model.datasources[0].ConnectionString = $newConnectionString
$svr.Databases[1].Update([Microsoft.AnalysisServices.UpdateOptions]::ExpandFull)

Your problem is primarily a syntax problem:

$svr.Databases[1].model.datasources[0].Update(UpdateOptions.ExpandFull)

The above is a .NET method call, which PowerShell parses in expression mode, which causes UpdateOptions.ExpandFull to report a syntax error.

In expression mode:

  • references to types such as UpdateOptions must be enclosed in [...]; e.g., [UpdateOptions]

  • references to static members of that type must be referenced via the :: operator; e.g. [UpdateOptions]::ExpandFull

That said, you must:

  • either: use the full type name, [Microsoft.AnalysisServices.UpdateOptions]::ExpandFull, as in Mötz' helpful answer.

  • or, in PSv5+: by placing a using namespace Microsoft.AnalysisServices statement at the start of the script, you can make the more concise [UpdateOptions]::ExpandFull work.

PowerShell offers a more convenient alternative, however: you can simply specify the enumeration value's symbolic name as a string - 'ExpandFull' - and PowerShell will automatically perform the conversion for you:

$svr.Databases[1].model.datasources[0].Update('ExpandFull')

You don't even need to know the enumeration's type name for this to work (though, if you do know it, using it in a language-aware editor such as Visual Studio Code can provide you with IntelliSense).

Related