Reputation: 3541
i am trying to add roles and members to a tabular database (cube)
$Server = new-Object Microsoft.AnalysisServices.Tabular.Server
$Server.Connect("$server")
$TabDB = $Tabular_Analysis_Server.Databases[$DB]
[Microsoft.AnalysisServices.Tabular.ModelRole] $AddRole = new-Object([Microsoft.AnalysisServices.Tabular.ModelRole])("NewRole1")
$AddRole.Members.Add("member1")
$TabDB.Roles.Add($AddRole)
$AddRole.Update()
I get this error:
new-Object : Cannot find an overload for "ModelRole" and the argument count: "1". and
This $TabDB.Model.Roles.members
gives me the roles and members just fine
if i try doing it this way:
$TabDB.Model.roles.Add("newrole1")
I get this error
Cannot find an overload for "Add" and the argument count: "1".
This $TabDB.Model.roles.Add()
results in
OverloadDefinitions
-------------------
void Add(Microsoft.AnalysisServices.Tabular.ModelRole metadataObject)
void ICollection[ModelRole].Add(Microsoft.AnalysisServices.Tabular.ModelRole item)
i found a script here but this is for early cube models (1103 and below) so it doesnt work on tabular models
https://bhavikmerchant.wordpress.com/2010/09/06/adding-ssas-roles-via-powershell/
UPDATE: following the MADMagician's answer, i am able to see this
Upvotes: 0
Views: 1653
Reputation: 36322
According to the documentation for the ModelRole class, the constructor doesn't accept any arguments like the older Role class did. You'll have to create a blank ModelRole, update any properties you want, then add it to the ModelRoleCollection.
$AddRole = new-Object Microsoft.AnalysisServices.Tabular.ModelRole
$AddRole.Name = 'NewRole1'
$RoleMember = New-Object Microsoft.AnalysisServices.Tabular.ModelRoleMember
$RoleMember.MemberName = 'member1'
$AddRole.Members.Add($RoleMember)
$TabDB.Model.Roles.Add($AddRole)
I don't actually have anything to test on, but the above should create a role, then a member, add the member to the role, then add the role to your database if I correctly understand the documentation that I linked.
As noted, there is not a constructor for ModelRoleMember, instead you have to use the derived classes that do have a constructor:
$RoleMember = New-Object Microsoft.AnalysisServices.Tabular.ExternalModelRoleMember
or
$RoleMember = New-Object Microsoft.AnalysisServices.Tabular.WindowsModelRoleMember
As for adding permissions you'll want to reference the documentation. It looks like you'll have to make Microsoft.AnalysisServices.Tabular.TablePermission
objects, set their properties, and then add them to the TablePermissions property of $AddRole
.
Upvotes: 1