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
Clear-Host
$creds = (Get-Credential)
Clear-Host
$addedUser = Read-Host ("User to add to groups")
$copiedUser = Read-Host ("User to copy groups from")
Write-Host
Write-Host
Write-Host "Working on it..." -ForegroundColor Yellow
Write-Host
Write-Host
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.

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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