Skip to content

Instantly share code, notes, and snippets.

@dgosbell
Created January 15, 2019 22:09
Show Gist options
  • Save dgosbell/b1d7991856de6f871497b4217bde96d3 to your computer and use it in GitHub Desktop.
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
#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()
@dgosbell
Copy link
Author

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment