In SQL Server SSAS I want to do a db restore from server A to server B, where DB already exists on server B. I was wondering if it's possible to script database permissions, so I can later run the script on server B to apply the original settings.
I was playing around with AMO, but I have limited programming knowledge, so not entirely sure how it works.
I know I can access this information:
[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.AnalysisServices”)
$SSASServer = New-Object Microsoft.AnalysisServices.Server
$SSASServerName = 'serverNameA\PRD'
$SSASServer.Connect($SSASServerName)
$SSASServer.Version
$DBName = 'DB_A_PRD'
$SSASDatabase = $SSASServer.Databases.Item($DBName)
$SSASDatabase.Refresh()
so later I can get all details about specific role
foreach ($role in $SSASDatabase.Roles) {Write-Host $role.Name}
$SSASDatabase.DatabasePermissions.FindByRole($role.ID)
Now I can recreate role on the server B
$roleToCreate = new-Object([Microsoft.AnalysisServices.Role])($var)
$SSASDatabase.Roles.Add($roleToCreate)
$roleToCreate.Update()
And here's where I am lost. How should I properly assign Administer, or Process permissions to this $roleToCreate?
I've seen another user who applied Read settings this way, but I did not find way do to the same for Administer or Process permissions:
$dbperm = $SSASDatabase.DatabasePermissions.Add($roleToCreate.ID)
$dbperm.Read = [Microsoft.AnalysisServices.ReadAccess]::Allowed
From what I've read here: https://learn.microsoft.com/en-us/analysis-services/amo/programming-amo-security-objects?view=sql-analysis-services-2022 it is possible, but I am not sure how to make it work in PowerShell.
I cannot do it as $dbpermissions.Process = True, ps won't recognize it. I imagine I need to do something similar as with enums with Read rights, but I don't know how.
I was using this documentation for refrence: https://learn.microsoft.com/en-us/dotnet/api/microsoft.analysisservices?view=analysisservices-dotnet
1条答案
按热度按时间uwopmtnx1#
I had difficulty adding roles with
$SSASDatabase.Roles.Add($roleToCreate)
. It would log a 0 to the terminal, indicating that nothing had been added.I decided to move on and found a different approach with TMSL. This solution creates a new role, but you can also amend it to createOrReplace.
Useful docs
https://learn.microsoft.com/en-us/analysis-services/tmsl/roles-object-tmsl?view=asallproducts-allversions
https://learn.microsoft.com/en-us/analysis-services/tmsl/createorreplace-command-tmsl?view=asallproducts-allversions