0 votes

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 a powershell script, however when we tried to create a custom command in Adaxes we received the following errors.

Powershell script is:

$verbose = $true 
Set-Alias read Read-Host 
$logger = ".\user_anlage.txt" 

# Import Module for ActiveDirectory 
Import-Module ActiveDirectory 
Clear-Host 

function message($message) { 
    write-host $message -f "Yellow" 
} 

function print_groups($username) { 
    $groups = Get-ADPrincipalGroupMembership $username 
    foreach ($g in $groups) {write " + $($g.name)"} 
} 

try { 
    message "`Copycat! Copy group memberships of user A to B`n" 

    $username = read 'enter username' 
    message "User: $username`n" 
    print_groups $username 

    $option = read "`ncopy to user? (y|n)" 
    if($option -eq "y") { 
        do { 
            $copy_user = read "enter username" 
            message "User: $copy_user`n" 
            $groups = Get-ADPrincipalGroupMembership $username 

            try { 
                Add-ADPrincipalGroupMembership $copy_user -MemberOf $groups -ErrorAction SilentlyContinue -WarningAction SilentlyContinue 
            } 
            catch { message " + " } 

            print_groups $copy_user 
            $option = read "`ncopy to user? (y|n)" 
        } 
        while($option -eq "y") 
    } 

    # script finished 
    message "`nFantastic!`n" 

} 
catch { 
    Write-Host $Error[0].Exception; 
    write-warning "I'm sorry, Jay. I'm afraid I can't do that." 
} 

by (3.2k points)

1 Answer

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

Hello,

Have a look at the following script in our repository: http://www.adaxes.com/script-repository ... ip-s32.htm.

Related questions

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

Hello I am trying to set up a script to copy the 'Members Of' from specific accounts to a new user account after creating the user. Something very similar to this: https:/ ... to the ever changing nature of the business. Is someone able to help me with this?

asked May 28, 2020 by adantona (40 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 (480 points)
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

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 ... identity in the error message start with 'user;'? What is the correct way to accomplish this?

asked Aug 27, 2019 by ngb (290 points)
3,541 questions
3,232 answers
8,225 comments
547,802 users