Remove method not working

i know this is powershell forum mainly, but since i havent received much help elsewhere (

i wont lose anything by posting here as lost shot at this.

also the code is pretty much powershell so why not :slight_smile: although i can understand if people cant help with this since its also SSAS

For some reason, the Remove() is not working properly. I keep reconnecting the server and checking if the ID gets removed and its not!

$ssasInstance = "<ssas instance name>"
$accountName= "<domain\user>"
Import-Module SqlServer
[Microsoft.AnalysisServices.Server]$SSASserver = New-Object ([Microsoft.AnalysisServices.Server])
$role= $SSASserver.Roles["Administrators"]

there is no errors or anything. i did a conditional statement to check if ID exists, and if it does, remove and output removed!

i do get output

removed ID!
but the ID is not really getting removed!

I have tried ADD, so that i know nothing is wrong with the script, and add works! only remove for some reason is not workingā€¦

on technet, Zoe misunderstood my post and thought i am referring to database members/roles. i am referring to server level administrators

i am using the code from here,

but this is for Adding users. Adding works just fine as i had mentioned, so i simply found that there is also remove(), and instead of add made the code remove. but i check the server and it still doesnt get removed. is the method bugged?

any reason you are not trying to use the built-in powershell cmdlet for this?

assuming you have 5.1 installed.

Here is a post that does it by index:

They also indicate that the Remove method does not work for a name reference, so maybe try:

$ssasInstance = ""
$accountName= ""
Import-Module SqlServer
[Microsoft.AnalysisServices.Server]$SSASserver = New-Object ([Microsoft.AnalysisServices.Server])
$role= $SSASserver.Roles["Administrators"]

foreach ($mbr in $role.Members) {
    if ($mbr.Name -eq $accountName) {

[quote quote=144287]any reason you are not trying to use the built-in powershell cmdlet for this?

assuming you have 5.1 installed.


  1. hmm interestingā€¦I wasnt aware of it

  2. i tried it, didnt really work eitherā€¦how doe sit even know that its removing from the server? i dont see an SSAS server parameter optionā€¦

[quote quote=144288][/quote]
Method invocation failed because [Microsoft.AnalysisServices.Role] does not contain a method named ā€˜Removeā€™.



This is an unfortunate confluence of circumstances: when you do


This works because, under water, the string ā€œmemberā€ is implicitly converted by PowerShell to a RoleMember with a Name of member and an empty Sid. All fine. However, if you then do


Nothing happens, because you will create a new RoleMember instance, and since RoleMember has no implementation of .Equals() (a fairly bizarre oversight), different instances will never be considered the same.

This means you can only remove members by getting the actual instance in the collection (or by index, I suppose):

$member = $role.Members.Where{$_.Name -eq "member"} | Select -First 1

Note that you will not get an error if there is no such member (because Remove allows $null, again in a rather bizarre oversight), so you may want to check for $member -eq $null if you want to verify that.

Definitely do not use Remove-LocalGroupMember ā€“ that cmdlet is part of a completely different moduleand removes members from local Windows groups, not SSAS roles.

ahh sorry, i saw ā€œserver level administratorsā€
and interpreted that to be the local administrators group on the windows server.

glad you found an answer