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 {    
    $group.Remove($_.ADsPath)    
    $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 (90 points)

1 Answer

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

Hello,

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.

0

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

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 (440 points)
0 votes
1 answer

We have several contractors that come and go, it would be helpful to have a custom command that will copy only the member of groups from one user to another. We have done this previously with ... ; write-warning "I'm sorry, Jay. I'm afraid I can't do that." }

asked Jan 9, 2017 by willy-wally (3.2k points)
2,756 questions
2,490 answers
6,519 comments
1,457,561 users