This script is very handy in dayli business, when you need to remove multiple users from an AD-Group.
In the userlist the users can be specified with the samAccountName.
Of course there is the possibility to fill “$UserList” variable with a list e.g. a CSV-File. In this case you can Use the function “Import-Csv” which is an out of the Box Powershell feature.
#13.11.2018 by Jeremias Kühnis
#Remove AD-Groupmemership
$ADGroup = "someAdGroupName"
$Userlist = @(
"SamAccountName1"
"SamAccountName2"
"SamAccountName3"
)
$Userlist | % {Remove-ADGroupMember -Identity $ADGroup -Members $_ -Confirm:$false}