Remove users from all AD groups

  • Last update on September 26th, 2024

Custom actions are not available in the Essentials solution.

 

If you are looking for a way to remove users from all AD groups, you can use the following script in a CoreView custom action:

{
 "id": "2d260602-3ce4-484b-96d5-e08ade0bef3b",
 "title": "Remove all AD group memberships v3",
 "description": "Script will remove all AD group memberships for 1 user",
 "lastModified": "2022-04-22T13:56:44.0380000Z",
 "target": "None",
 "tags": [],
 "vars": [
 {
 "name": "SAMAccountName",
 "type": "string",
 "isRequired": true
 }
 ],
 "params": [],
 "columns": {},
 "version": 4,
 "statement": "param ([string]$SAMAccountName)\r\n\r\n$members = Get-ADUser -Identity $SAMAccountName -Properties MemberOf\n\n foreach( $group in $members.MemberOf){\n Remove-ADGroupMember -identity $group -Members $SAMAccountName -Confirm:$false\n\n }"
}