How to remove all users from groups
I would like to remove all users from groups. My issue is the fact that I have GroupNames that contain '@' so it fails... any help will be appreciate. Thanks
$groupNames = @"
Groups;
@Test-Group-FIN #fail
@Test-Group-HR #fail
SupportGAP #it works for this group
"@ | Convertfrom-csv -Delimiter ";"
#Remove members
foreach ($ADGroup in $groupNames) {
Get-ADGroupMember -Identity $ADGroup.Groups.Trim() | ForEach-Object {Remove-ADGroupMember $ADGroup.Groups.Trim() $_ -Confirm:$False }
}
Solution 1:
please try removing group members using the following method
$groups = @('@Test-Group-FIN','@Test-Group-HR','SupportGAP')
foreach ($group in $groups){
Get-ADGroup $group | Set-ADGroup -Clear member
}
please note that we are using here the ldap attribute member
not members