'Remove specific user from a numbered group that I don't know the number of

As Title states, I am trying to use Powershell to remove a user from an Active Directory group that has the naming scheme of Group # with group always being the same word but the # being anything 1-20. Not sure which group the specific user is a part of so I am trying to use a wildcard "*" but it doesn't seem to want to work with

Import-Module ActiveDirectory
Remove-ADGroupMember -Identity "Group *" -Members "test"

Thanks



Solution 1:[1]

The -Identity parameter is for when you have a single distinct group identity (a distinguished name, SAMAccountName, security identifier, or object GUID of an existing group).

Instead, use Get-ADGroup with the -Filter parameter to search for the relevant groups, then pipe them to Remove-ADGroupMember:

Get-ADGroup -Filter "Name -like 'Group *'" |Remove-ADGroupMember -Members "test"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mathias R. Jessen