Removing AD Group Members

by Dec 5, 2014

Module ActiveDirectory

To remove one or many users from an Active Directory group, try this approach:

$user = @()
$user += Get-ADUser -Filter { Name -like 'H*'} 
$user += Get-ADUser -Filter { Name -like '*ll*'} 

Remove-ADGroupMember -Identity 'SomeGroup' -Members $user 

This would first find all users with a given pattern in their names, then submit the user list to Remove-ADGroupMember to exclude the users from that group.

Note the use of an empty array. An empty array can then be filled with the operator “+=” in one or many steps, and this operator accepts individual users as well as an array. So you can add single users or a number of users to your user list–for example, the result of a filter query.

Twitter This Tip! ReTweet this Tip!