Continuing my previous post https://rachmadona.net/script-for-creating-bulk-users-for-windows-using-powershell/ regarding with provisioning bulk users in AD using PowerShell, in this article i’ll explain how to assign/remove group for such particular OU. Again, please bear in mind that you have to install PowerShell in order to run this custom script.

If you don’t know how to get the OU detail in distinguishName (DN) format, just right click on desire OU then select Attribute Editor tab.

$ou = "OU=Users,DC=contoso,DC=com"   #change this ou path as you requires
 $groupname = "Internet"   #change this group name as you desire
 $targetuser = Get-ADUser -SearchBase $ou -Filter *
 Add-ADGroupMember -Identity $groupname -Members $targetuser

Above example will help you to assign group “Internet” into whole users located on OU: Users. You may have to adjust the script based on your needed accordingly.

In addition, please check below script in order to remove group for particular OU. In this example i will remove the group called “Internet” for users located on OU:Users.

$OU = "OU=Users,DC=contoso,DC=com"
 $Users = Get-ADUser -SearchBase $OU -filter *
 foreach ($user in $Users) {
  Remove-ADGroupMember -Identity "CN=Internet,DC=contoso,DC=com" -Members $Users -confirm:$false
 }

End.