{"id":2740,"date":"2020-01-11T10:46:39","date_gmt":"2020-01-11T03:46:39","guid":{"rendered":"http:\/\/rachmadona.net\/?p=2740"},"modified":"2020-01-11T10:46:39","modified_gmt":"2020-01-11T03:46:39","slug":"add-remove-group-bulk-users-in-active-directory-using-powershell","status":"publish","type":"post","link":"https:\/\/rachmadona.net\/?p=2740","title":{"rendered":"Add\/Remove Group Bulk Users in Active Directory Using PowerShell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Continuing my previous post  <a href=\"https:\/\/rachmadona.net\/script-for-creating-bulk-users-for-windows-using-powershell\/\">https:\/\/rachmadona.net\/script-for-creating-bulk-users-for-windows-using-powershell\/<\/a> regarding with provisioning bulk users in AD using PowerShell, in this article i&#8217;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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you don&#8217;t know how to get the OU detail in distinguishName (DN) format, just right click on desire OU then select Attribute Editor tab.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/rachmadona.net\/wp-content\/uploads\/2020\/01\/image-5.png\" alt=\"\" class=\"wp-image-2768\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>$ou = \"OU=Users,DC=contoso,DC=com\"   #change this ou path as you requires\n $groupname = \"Internet\"   #change this group name as you desire\n $targetuser = Get-ADUser -SearchBase $ou -Filter *\n Add-ADGroupMember -Identity $groupname -Members $targetuser<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Above example will help you to assign group &#8220;Internet&#8221; into whole users located on OU: Users. You may have to adjust the script based on your needed accordingly.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, please check below script in order to remove group for particular OU. In this example i will remove the group called &#8220;Internet&#8221; for users located on OU:Users.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$OU = \"OU=Users,DC=contoso,DC=com\"\n $Users = Get-ADUser -SearchBase $OU -filter *\n foreach ($user in $Users) {\n  Remove-ADGroupMember -Identity \"CN=Internet,DC=contoso,DC=com\" -Members $Users -confirm:$false\n }<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">End.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;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&#8217;t know how to get the OU detail&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,27],"tags":[57,327,506],"class_list":["post-2740","post","type-post","status-publish","format-standard","hentry","category-server","category-windows","tag-adding-group-via-powershell","tag-powershell","tag-windows-server-2012"],"_links":{"self":[{"href":"https:\/\/rachmadona.net\/index.php?rest_route=\/wp\/v2\/posts\/2740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rachmadona.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rachmadona.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rachmadona.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rachmadona.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2740"}],"version-history":[{"count":0,"href":"https:\/\/rachmadona.net\/index.php?rest_route=\/wp\/v2\/posts\/2740\/revisions"}],"wp:attachment":[{"href":"https:\/\/rachmadona.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rachmadona.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rachmadona.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}