Copy User’s Groups to Another User

Applies to Active Directory, User Management
Modules needed: ActiveDirectory

This is a very useful script if you find yourself needing to add a user to all the groups another user is a part of. Typically, you could just copy the user in Active Directory to make the new user. But in this case, I was asked to do this for an existing user. There’s no simple way to do this within Active Directory, but this quick script gets it done.

The script asks for the user needing to be added, and the user to copy the groups from.

Import-Module ActiveDirectory
$creds = (Get-Credential)
$addedUser = Read-Host ("User to add to groups")
$copiedUser = Read-Host ("User to copy groups from")
Write-Host "Working on it..." -ForegroundColor Yellow
Get-ADUser -identity $copiedUser -Properties memberof | Select-Object -ExpandProperty memberof | Add-ADGroupMember -Members $addedUser -Credential $creds -Passthru | Format-Table -Property Name,GroupCategory,GroupScope,DistinguishedName -AutoSize

At the end of the script, the groups the user was added to are shown.


One thought on “Copy User’s Groups to Another User

  1. Anonymous September 9, 2019 / 6:39 am

    Thanks, this saves me some tim e :à


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s