Searching Azure AD groups for multiple strings

I need to retrieve a list of all Azure AD groups with the naming convention Department_XY_{GroupName}_Member.

I have tried using the -Filter parameter of the Get-AzureADGroup Cmdlet, but I have encountered some errors. For example, Get-AzureADGroup -Filter "startswith(DisplayName, 'Department_XY')" works fine, but Get-AzureADGroup -Filter "endswith(DisplayName, 'Member') throws an error.

I have the AzureAD module installed. Is there a better way to do this?

Yes, you can use the -SearchString parameter of the Get-AzureADGroup cmdlet to search for groups with a specific naming convention. Try the following command:

Get-AzureADGroup -SearchString "Department_XY_*_Member"

This will retrieve a list of all Azure AD groups with names that start with “Department_XY_”, end with “_Member”, and have any value for the group name in between.