Occasionally groups may become obsolete or are never populated with members. It can be interesting to find out how many groups are in your organization that have no members, as action can be taken on it based on the output.
Overview of articles in this series |
Active Directory Friday: Find groups with no members |
Active Directory Friday: Principal group membership |
Active Directory Friday: User account group membership |
Because of the nature of how group membership is defined this article will be the first in a series of three. In this article I will show how group membership can be determined using an LDAP queries. The next article in this series will go into principal group membership and its implications and the final article will go into constructed attributes and how to work with constructed attributes, specifically the memberof attribute.
In this article I will give a a number of examples that can be used to determine which groups are empty. Using Get-ADGroup the following command can be executed to retrieve memberless groups:
Get-ADGroup -LDAPFilter '(!(member=*))' |
Get-ADGroup -LDAPFilter '(!(member=*))'

Alternatively the DirectoryServices.DirectorySearcher object can be used to achieve a similar result:
(New-Object DirectoryServices.DirectorySearcher -Property @{
Filter = '(&(objectClass=group)(!(member=*)))'
PageSize = 100
}).FindAll() |
(New-Object DirectoryServices.DirectorySearcher -Property @{
Filter = '(&(objectClass=group)(!(member=*)))'
PageSize = 100
}).FindAll()
The [adsisearcher] type accelerator is another interesting alternative for this purpose, here is an example:
([adsisearcher]'(&(objectClass=group)(!(member=*)))').FindAll() |
([adsisearcher]'(&(objectClass=group)(!(member=*)))').FindAll()
The problem with the above examples however, is that some groups will show up as being empty, for example the Domain Users group. Next week I will go into Principal group membership, what this is and how to query for this and by doing so generate more accurate results in regards to group membership.
For more information about the topics discussed in this article, please have a look at the following resources:
Like this:
Like Loading...