This project has moved. For the latest updates, please go here.
1

Closed

Remove from Group Membership not working

description

I have used the working with multivalued attributes to add users to Groups. But when I do Remove it does not work.

$obj = Get-Resource -ObjectType Group -AttributeName ObjectID -AttributeValue $object
$obj.ExplicitMember.Remove($attributeValue)
Save-Resource $obj

If I do
$obj.ExplicitMember.Add($attributeValue)

I add a member successfully. Is the remove format different? Or a code issue?

Thanks
Closed Jan 11, 2016 at 8:17 PM by ryannewington

comments

ryannewington wrote Oct 3, 2015 at 3:04 AM

Hi,

Thanks for the report. That certainly doesn't seem right.

Can you check if getting the object with the following command

$obj = Get-Resource -ObjectType Group -AttributeName ObjectID -AttributeValue $object -AttributesToGet @("ExplicitMember")

works when you call the Remove method on ExplicitMember?

myFIMcodeplex wrote Oct 3, 2015 at 9:32 AM

Hi

I just tried that and it made no difference the Remove still did not work.

Thanks

ryannewington wrote Oct 3, 2015 at 9:04 PM

Found the issue. The underlying array was looking to remove an objectID, rather than the object. ($attributeValue.ObjectID would have worked.)

Build 5755 has been fixed to allow the use of the object itself, as well as the object ID, when removing an attribute value from a multi-valued reference attribute.

myFIMcodeplex wrote Oct 3, 2015 at 10:55 PM

Hi Ryan
What is different here is that one has to get the resource first before doing the remove.

If you do a Write-host $obj.ExplicitMember you will see the ObjectID but you cannot do a
$obj.ExplicitMember.Remove("8158c61c-b88d-4271-9cd2-864348fd35a1")

you have to get the resource first so it will be
$obj2=Get-Resource -ObjectType Person -AttributeName ObjectID -AttributeValue 8158c61c-b88d-4271-9cd2-864348fd35a1

Then do either one of these
$obj.ExplicitMember.Remove($obj2.objectid)
or
$obj.ExplicitMember.Remove($obj2)

But for the Add member to Group you can simply do this
$obj.ExplicitMember.Add("8158c61c-b88d-4271-9cd2-864348fd35a1")
And that works

Why is the Add and remove behavior different? Would be nice if one can remove with just the ObjectID value instead of another extra step of getting the resource first. The Import-FImConfig did remove with just the ObjectID value.

Thanks

ryannewington wrote Oct 3, 2015 at 11:42 PM

So the reason is that there is an ArrayList 'proxy' object that holds the changes before submitting them back to the 'real' object. The ArrayList takes a type of 'object' (so - anything) and the backend object knows how to convert any known type to the right value for references when it gets it.

However, 'remove' is a function of the array list itself. It doesn't get to the backend object for processing. It's looking for an exact object type match. I've added support in for GUID in the release you are using. You should be able to do this as a workaround for now.
$obj.ExplicitMember.Remove([Guid]"8158c61c-b88d-4271-9cd2-864348fd35a1")
or remove it by its index
$obj.ExplicitMember.Remove($obj.ExplicitMember[0])

I agree its not ideal, I'll re-open the issue, and i'll look to improvise better support for this. Add and Remove should behave the same.

ryannewington wrote Oct 8, 2015 at 10:38 PM

Added support for string, GUID, RMObject, and UniqueIdentifier values in the Remove() function as of version 1.0.5760

myFIMcodeplex wrote Oct 8, 2015 at 11:29 PM

Thanks Ryan! Tested it and it works well

$obj.ExplicitMember.Remove("8158c61c-b88d-4271-9cd2-864348fd35a1")

removes user from Group