troubleshooting Question

Copy one user's AD groups to another user

Avatar of Michael Graham
Michael GrahamFlag for United States of America asked on
Active DirectoryPowershell
1 Comment1 Solution64 ViewsLast Modified:
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 = ""
$UserAddingGroups = ""
Get-ADUser -LDAPFilter "(&(UserPrincipalName=$User))" -Properties * | Select-Object MemberOf | 
   ForEach-Object { $_.MemberOf | Add-ADGroupMember -Identity $_.MemberOf -Members $UserAddingGroups -Confirm:$true }

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 }
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros