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?
This is an unfortunate confluence of circumstances: when you do
$role.Members.Add("member")
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
$role.Members.Remove("member")
Nothing happens, because you will create a newRoleMember 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):
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.