One way of getting rid of excessive groups is to find which groups have similar membership. The simplest case is when the list of direct members of a group matches another group’s list.
Groups with same direct members are not always a bad practice but they definitely need review. As a result of this review one or a few of such groups might be considered duplicate. In this case all references to the duplicate groups must be replaced with another group with similar members. Not only it will help you simplify on-going management of remaining groups but it will also reduce a risk of “token bloat” issues stemming from having too many groups a user is a member of.
Here is a PowerShell code snippet that finds groups with matching direct members.
Once groups have been fetched the script builds a map of unique group memberships. The sorted list of group members serves as a key to that map. This way, when another group with the same list of direct members is found, the map looks up a matching group by the same key and adds another group into the same map element.
The output of this script shows sets of groups separated by a new line. Each set represents groups that have matching group members. Here is an example of the script output: