Avatar of Michael Graham
Michael GrahamFlag for United States of America

asked on 

Copy one user's AD groups to another user

I am trying to copy 1 users AD Security Groups to a 2nd user I created via PowerShell. I know I could copy the user from ADUC but I am trying to do this with PowerShell. The user I am trying to copy has 8 groups and I will need to create multiple users with the same permissions so any help would be appreciated since this will save me considerable time and prevent accidentally adding the incorrect groups.

$User = "user1@domain.com"
$UserAddingGroups = "user2@domain.com"
Get-ADUser -LDAPFilter "(&(UserPrincipalName=$User))" -Properties * | Select-Object MemberOf | 
   ForEach-Object { $_.MemberOf | Add-ADGroupMember -Identity $_.MemberOf -Members $UserAddingGroups -Confirm:$true }

Open in new window

I can get the list of groups by typing a variation of the above, so I think I am close.
Get-ADUser -LDAPFilter "(&(UserPrincipalName=$user))" -Properties * | Select-Object MemberOf | 
   ForEach-Object { $_.MemberOf | Format-Table }

Open in new window

PowershellActive Directory

Avatar of undefined
Last Comment
Michael Graham
Avatar of Michael Graham
Michael Graham
Flag of United States of America image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Active Directory
Active Directory

Active Directory (AD) is a Microsoft brand for identity-related capabilities. In the on-premises world, Windows Server AD provides a set of identity capabilities and services, and is hugely popular (88% of Fortune 1000 and 95% of enterprises use AD). This topic includes all things Active Directory including DNS, Group Policy, DFS, troubleshooting, ADFS, and all other topics under the Microsoft AD and identity umbrella.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo