Remove Active Directory Group from a list of AD users using Powershell

Powershell script to remove an active directory group from list of AD users.

upnlist.txt = Contains list of user's UPN 
<GroupName> = This group will be removed 
from the user's mentioned in the upnlist.txt file #> 
$upnlist = Get-Content 'c:\temp\upnlist.txt' 
Foreach ($upn in $upnlist) 
{ $var = Get-ADUser -Filter "UserPrincipalName -eq '$upn'"
Remove-ADgroupmember -identity '<GroupName>' -members $var -Confim:$false }

Leave a Comment