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

Hi Darren Gosbell, nice code it helps me a lot. i am using your code for warming our ssas cube users .
i have question about it.
is it possible to run this code in parallel(i don't know much about powershell )?because we have about 300 users and warming each user takes about 1 minute.and whole process take about 3-4 hours

@abianari
Copy link

@dgosbell
Copy link
Author

It probably is possible to run this in parallel, but you'd want to keep an eye on the resource usage on your server to make sure that you don't overload it. ADOMD does not have async methods so you'd have to use a Powershell cmdlet called Start-Job which can start background tasks. However this cmdlet is quite expensive to run so you would want to split the user list into a number of smaller segments and run a task per segment. I'd probably start with 2-3 segments to see if the concept works and then start increasing the number of jobs until you stop see an improvement in the time taken.

@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