Copy on-premise user group membership

  • Last update on September 26th, 2024

Custom actions are not available in the Essentials solution.

If you have a Professional solution, you must purchase the Hybrid add-on to create this custom action.

 

If you are looking for a way to copy an existing AD user group membership 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 a CoreView custom action:

{
 "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"
}