Created
January 15, 2019 22:09
-
-
Save dgosbell/b1d7991856de6f871497b4217bde96d3 to your computer and use it in GitHub Desktop.
A simple example of how to manually deploy a model.bim file using Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -Version 3.0 | |
param( | |
[Parameter(Mandatory=$true)] | |
[string]$serverName, | |
[Parameter(Mandatory=$true)] | |
[string]$databaseName, | |
[Parameter(Mandatory=$true)] | |
[string]$pathToBimFile | |
) | |
<# | |
.SYNOPSIS | |
Deploys a model.bim file to a server | |
.DESCRIPTION | |
Adds a file name extension to a supplied name. | |
Takes any strings for the file name or extension. | |
.PARAMETER serverName | |
The name of the SSAS server which is the deployment target | |
.PARAMETER databaseName | |
The name to give to the database we are deploying | |
.PARAMETER pathToBimFile | |
The full path the model.bim file | |
.INPUTS | |
None. You cannot pipe objects to Add-Extension. | |
.OUTPUTS | |
None | |
.EXAMPLE | |
The following example will deploy "c:\temp\model.bim" to the localhost\tab17 server | |
as a database called "Test" | |
C:\PS>.\deploy-bimfile.ps1 "localhost\tab17" "Test" "c:\temp\model.bim" | |
#> | |
## check if the path to the .bim file exists | |
if (-not (test-path $pathToBimFile)) { | |
write-error "Could not find the bim file: $pathToBimFile" | |
exit 1 | |
} | |
## Load AMO Library | |
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices") > $null | |
## Connect to Server | |
$server = New-Object Microsoft.AnalysisServices.Server | |
$server.connect($serverName) | |
$json = Get-Content $pathToBimFile -Raw | |
$db = [Microsoft.AnalysisServices.JsonSerializer]::DeserializeDatabase($json) | |
$db.Name = $databaseName | |
$db.ID = $databaseName | |
#### | |
## at this point we have a Database object and we can alter | |
## any properties such as data source connection strings | |
## before generating the final createOrReplace script | |
#### | |
$script = [Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrReplace($db) | |
$server.Execute($script) | |
$server.Disconnect() |
@Kazanskyi - that probably means you have an older version of the client libraries installed on your machine. The simplest fix would be to install the most recent version by down loading the AMO installer from here https://docs.microsoft.com/en-us/analysis-services/client-libraries?view=asallproducts-allversions
Thanks @dgosbell . Works well!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @dgosbell,
Thank you for your script!
I am trying to run it for PowerBI SSAS model and I gen an error:
Unable to find type [Microsoft.AnalysisServices.JsonSerializer].
Could you help to resolve it? I can't find a simple answer online.