Skip to content

Instantly share code, notes, and snippets.

@dgosbell
Last active July 27, 2019 07:28
Show Gist options
  • Save dgosbell/969cb76ae0f0f45a9fb45942e2fb0f31 to your computer and use it in GitHub Desktop.
Save dgosbell/969cb76ae0f0f45a9fb45942e2fb0f31 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
Warms the SSAS permissions when using a dynamic security role
.NOTES
Author: Darren Gosbell
Date: 6 Jul 2016
.DESCRIPTION
Warms the Global Scope cache for a list of users. This is useful when
the first connection on a cold cache per user is slow due to evaluation
of a dynamic security role. For production usage it would make sense
to get the list of user accounts by running a SQL query against your
user security table rather than hard coding it.
NOTE: MUST be run by an account with SSAS Server admin priviledges
#>
## the following 4 variables need to be updated for your environment
$server = "localhost\tab12"
$database = "AW Internet Sales Tabular Model 2014"
$model = "Model"
$users = @(
"mydomain\user1",
"mydomain\user2"
)
$userCnt = 0
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.adomdclient") > $NULL
foreach ($user in $users) {
$userCnt++
$connStr = "data source=$server;initial catalog=$database;EffectiveUserName=$user"
$cnn = new-object Microsoft.AnalysisServices.adomdclient.adomdconnection($connStr)
$cmd = $cnn.CreateCommand()
$cmd.CommandText = "select {} on 0 FROM [$model]"
$da = new-Object Microsoft.AnalysisServices.AdomdClient.AdomdDataAdapter($cmd)
$ds = new-Object System.Data.DataSet
$da.Fill($ds) > $NULL
$cnn.Close()
write-output "cache primed for user: $user"
Write-Progress -Status "Priming User Caches" -Activity "User: $user" -PercentComplete (($userCnt / $users.Count) * 100)
}
@abianari
Copy link

thanks a lot for your detailed explanation.

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