On-Premise AD: Copy Group Memberships- Custom Action

Modified on Thu, 03 Nov 2022 at 09:55 AM

If you are looking for a way to copy an existing AD user group memberships so it can be applied to a new, target user, you can use the following:

In Powershell:

#One line to get what the user member of.

Get-ADUser -Identity <UserID> -Properties memberof | Select-Object -ExpandProperty memberof

#One line to copy the membership from one user to another.

Get-ADUser -Identity <UserID> -Properties memberof | Select-Object -ExpandProperty memberof |  Add-ADGroupMember -Members <New UserID>

In Coreview:

   "id": "1648cf21-40cb-455a-b375-7902a34754df",
   "title": "Copy group membership",
   "lastModified": "2022-02-07T10:02:21.4980000Z",
   "target": "None",
   "tags": [],
   "vars": [
         "name": "SourceUser",
         "type": "string",
         "isRequired": true
         "name": "TargetUser",
         "type": "string",
         "isRequired": true
   "params": [],
   "columns": {},
   "version": 2,
   "statement": "param ([string]$SourceUser, [string]$TargetUser)\r\n\r\n$groups = get-adprincipalgroupmembership $SourceUser | where-object {$_.name -ine \"Domain Users\"}\nAdd-ADPrincipalGroupMembership $TargetUser -memberof $groups.SamAccountName"

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article