Get-ADGroup -Filter Example

Get-ADGroup Filter Syntax

The PowerShell command Get-ADGroup is part of the Active Directory PowerShell module. Go to this article if you want to know how to install it.

To search effectively for groups in your Active Directory, you should use the Filter switch. Don’t extract all groups and then search the result set.

Use Get-ADGroup -Filter to search directly for improved performance.

Understand the Get-ADGroup Filter Parameter

With the many various filtering options available (LDAP filtering, oData v3.0 filtering, etc.), the filter switch often causes some confusion.

The filter switch used in the Get-ADGroup command uses the PowerShell expression language in the query string.

For example, this is different than, e.g., when using the Get-AzureADGroup command (which uses oData v3.0 filtering)!

The following operators should cover most of your needs:

OperatorMeaningSample expression
-eqEqual toName -eq “G.U.Marketing”
-neNot equal toGroupType -ne “-2147483640”
-gtGreater thanModified -gt “01-06-2021”
-geGreater than or equalCreated -ge “01-01-2018”
-ltLess thanModified -lt “01-02-2021”
-leLess than or equalCreated -le “01-01-2018”
-likeWildcard searchextensionAttribute1 -like “*”
-notlikeWildcard search with negationName -notlike “Exchange*”
-andAndName -like “G.U.*” -and Name -like “*legal*”
-orOrName -like “*marketing*” -or Name -like “*legal*”

Please notice the following in the above examples:

  • Enclose the compared value(s) in apostrophes
  • Use -like ‘*’ and -notlike ‘*’ to find empty or non-empty values

Below you have some code snippets that should point you in the right direction on how to structure your filters for your Get-ADGroup search queries:

Get-ADGroup -Filter 'Name -eq "G.U.Marketing"'
Get-ADGroup -Filter 'GroupType -ne "-2147483640"'
Get-ADGroup -Filter 'Modified -gt "01-06-2021"'
Get-ADGroup -Filter 'Created -ge "01-01-2018"'
Get-ADGroup -Filter 'Modified -lt "01-02-2021"'
Get-ADGroup -Filter 'Created -le "01-01-2018"'
Get-ADGroup -Filter 'extensionAttribute1 -like "*"'
Get-ADGroup -Filter 'Name -notlike "Exchange*"'
Get-ADGroup -Filter 'Name -like "G.U.*" -and Name -like "*legal*"'
Get-ADGroup -Filter 'Name -like "*marketing*" -or Name -like "*legal*"'

Summary

Using Get-ADGroup with the Filter option lets you easily retrieve the group objects you need. This feature is very nice for report building or doing bulk changes.

To make your admin life even easier, have a look at Easy365Manager.

Easy365Manager is a snap-in to AD Users & Computers that allows you to manage Office 365 mailboxes and licenses as part of your standard AD management.

Easy365Manager extends user properties with two new tabs, so you no longer have to switch between multiple tools to perform daily management:

easy365manager ui
User properties, "Office 365" tab
easy365manager ui
User properties, "Mailbox tab"

Imagine that you no longer have to log in to the Microsoft 365 Admin Center, the Exchange Online Admin Center, or the Azure Portal for daily user management.

You can even synchronize Azure AD Connect directly from user properties.

And you can remove your on-premises Exchange server to avoid all future zero-day exploits.

Try the 30-day trial now. It only takes a few minutes to install, and we guarantee you’ll be saving hours of work before the end of the week!

Did you like this post? Maybe your friends will too!