Assuming that you have the ActiveDirectory module installed, you can use the following one-liner to get the group membership information for a specific user in Active Directory and filter the results based on a specific naming pattern:

 

Get-ADPrincipalGroupMembership -Identity ‘username’ | Where-Object { $_.Name -like “*pattern*” } | Select-Object Name

 

Replace username with the name of the user you want to get the group membership information for, and replace pattern with the specific naming pattern that you want to filter the results by. This command will return all the group names that match the specified pattern for the specified user.

 

This is a PowerShell one-liner command used to retrieve Active Directory (AD) groups of a specific user whose username is specified by replacing the ‘username’ value.

Here’s a breakdown of what the command does:

  1. Get-ADPrincipalGroupMembership: This cmdlet is used to retrieve all the AD groups that a specified user is a member of.
  2. -Identity ‘username’: This parameter specifies the username of the user whose group memberships are to be retrieved.
  3. Where-Object { $_.Name -like “*pattern*” }: This cmdlet filters the results returned by Get-ADPrincipalGroupMembership to include only groups that have a name containing the “pattern” string.
  4. Select-Object Name: This cmdlet selects the “Name” property of the filtered AD groups and displays it as output.

So, the final output will display the names of all AD groups that the specified user is a member of and whose name contains the specified pattern.