We help IT Professionals succeed at work.

Powershell script to check no of members in each group and log the data with count and get the groups that has identical no of users and names.

Hi,

Powershell script to check no of members in each group and log the data with count and get the groups that has identical no of users and names.

I need to get this data to reduce groupswhich might have identical users. So can ask them to rename the group in such a way that we can delete the rest of the groups.

An help is of great use.

Regards
Sharath
Comment
Watch Question

Commented:
Would you like this for a particular OU, or to just start at the root fo your domain?

Author

Commented:
I want this for the root Domain one specific OU
Commented:
Below script will output a logfile (C:\temp\ADMembersCount.txt) containing:
Name,MemberCount
Groupname,15
Groupname,10
Groupname,9
etc..
Is this what you were looking for?

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchScope = "Subtree" 
$objSearcher.PageSize = 1000 
$objSearcher.Filter = "(objectCategory=group)"
$Results = $objSearcher.Findall()
$Array= ,"Name,MemberCount"
Foreach ($Group in $Results) {
$Name = $Group.Properties.samaccountname
$Count = $GRoup.properties.member.count
$array +=,"$Name,$Count"
}
$array | out-file "C:\temp\ADMembersCount.txt"

Open in new window

Author

Commented:
Thanks
But i want the duplicates as well
if a group has 3 memebrs then check if any other group has identical 3 members

Commented:
Oh Ok. So you really dont care about many members are in the group, you just want to know if their duplicate groups...
That would require pulling all groups and users, then comparing each group to another. How many groups do you have?  If this is a large domain, this may be unfeasable just due to the time it will take to process that much data.

Author

Commented:
I also want that
I have 800+ groups

Author

Commented:
Any views...

Commented:
Sorry, was out on vacation for a bit and forgot about this. I will try and whip up something for you today.

Author

Commented:
Any views...