Skip to content

PowerShell: Find all groups containing a specific string

Sometimes, you need a list of all groups whose name contain a specific string, whether that is in the beginning, middle, or end of the group name. As we’ve seen previously, looking up groups in PowerShell is done with the Get-ADGroup command. Adding the -filter parameter allows us to find groups that satisfy our needs. Using asterisks as wildcards, we can specify whether the string should be at the start, middle, or end:

Get-ADGroup -Filter "Name -like 'Beginning*'"
Get-ADGroup -Filter "Name -like '*Middle*'"
Get-ADGroup -Filter "Name -like '*End'"

If we add a pipe and “select” followed by the name of a property outputs results that satisfy the filter, showing the specified property only. It might look something like this:

PS C:\Users\USER> Get-ADGroup -Filter "Name -like 'adm*'" | select name

name                
----   
administrators
admins
administrative_users

The same method can be applied to the Get-ADUser query, to find users whose name satisfy the Filter criteria.

By posting a comment, you consent to our collecting the information you enter. See privacy policy for more information.

This site uses Akismet to reduce spam. Learn how your comment data is processed.