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 (280 points)

1 Answer

0 votes
by (182k 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 (3.3k 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 (4.9k 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 (14.9k points)
0 votes
1 answer

Hi, Group memberships are kept when using "User Copy" function. Is it possible to do the same thing between two existing users ? (custom commands or else) Thanks for your response, Yoann

asked Oct 4, 2012 by yoann.hamon (1.9k points)
0 votes
1 answer

Hi, I need to start Adaxes scheduled task from Powershell console running on another host. How can I do that?

asked May 21 by KIT (2.9k points)
2,251 questions
2,011 answers
5,504 comments
24,627 users