0 votes

I have a scheduled task that runs a Powershell script against an AD group, "Group 1". I need to get all of the members of Group 1, and add them to Group 2. The script below successfully removes the user from Group 1 but I get an error at the Add-AdmGroup member line:

Can't find an object with identity 'user;Adaxes://domain.com/CN=User Name,OU=Users,DC=domain,DC=com'. 
$group = $Context.TargetObject
$members = $group.Members()
$members | ForEach-Object {    
    $Context.LogMessage("Removed group member " + $_.Name, "Information")
    Add-AdmGroupMember "Group 2" $_    

Why does the identity in the error message start with 'user;'? What is the correct way to accomplish this?

by (130 points)

1 Answer

0 votes
by (250k points)
selected by
Best answer


Why does the identity in the error message start with 'user;'?

This happens because the object being removed from one group and added to another is a user account. The error itself occurs because the Members method returns objects that cannot be used in the Members parameter of the Add-AdmGroupMember cmdlet. For details, see https://www.adaxes.com/sdk/?Add-AdmGrou ... er_Members.

What is the correct way to accomplish this?

Have a look at the following script from our repository: https://www.adaxes.com/script-repositor ... s-s548.htm.


Thanks, that did it.

Related questions

0 votes
1 answer

Hello Back when we first started using Adaxes you created a couple of great scripts which worked together really well, the first one copied one users group membership and put in ... an addition to what groups the second user is already a member of? Thank you.

asked Aug 4, 2015 by CBurn (700 points)
0 votes
1 answer

Currently, when I disable a user account in Adaxes, the group memberships of the user remain intact. I'd like to automate the removal of group memberships such as distribution ... a list of groups/DL that the user was previously in and removed from. Thanks!

asked Nov 3, 2021 by jayden.ang (20 points)
0 votes
1 answer

HI Support, I'm looking for a business Rule that remove a user from a couple of groups after the User is added to a group. ie 1. The User MaxMi is added to the ... not able to create a powershell scripts for removing the added user from the other Groups. Thx,

asked Jan 4, 2016 by Napoleon (700 points)
0 votes
1 answer

We have a potentially complicated sitaution and so far I have no found a solution. Any suggestions will be greatly appreciated. We have specific security groups that ... or see any user details other than the memberships for these specific security groups.

asked Jan 2 by WannabeGuru (20 points)
0 votes
1 answer

goal is to copy groups from one user to another during the crete user process. I created a variable on the create user form to input the UPN of the ... primaryGroupToken") -eq $primaryGroupId) { continue } $group.Remove($Context.TargetObject.AdsPath) } }

asked Nov 30, 2021 by Derek.Axe (460 points)
3,063 questions
2,776 answers
429,047 users