BlazeGod10
BlazeGod10

Reputation: 1

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

Upvotes: 0

Views: 207

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174700

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"

Upvotes: 1

Related Questions