{"id":70813,"date":"2004-12-14T10:23:00","date_gmt":"2004-12-14T10:23:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/12\/14\/how-can-i-rename-an-active-directory-group\/"},"modified":"2004-12-14T10:23:00","modified_gmt":"2004-12-14T10:23:00","slug":"how-can-i-rename-an-active-directory-group","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-rename-an-active-directory-group\/","title":{"rendered":"How Can I Rename an Active Directory Group?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I rename an Active Directory group?<BR><BR>&#8212; CL<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, CL. This is actually pretty easy; as you\u2019ll see, it only takes two lines of code. It\u2019s not a hard problem, it\u2019s just a little bit tricky. That\u2019s because ADSI (at least when it comes to dealing with Active Directory) does not have a Rename method. Instead, you need to use the MoveHere method to \u201cmove\u201d the account from its current ADsPath to a new ADsPath. The trick is that the new path differs in only one respect: the CN (common name). Giving the object a new CN effectively renames it.<\/P>\n<P>Confused? We don\u2019t blame you. So let\u2019s give you an example. Suppose we have a group with an ADsPath similar to this (remember, the ADsPath is the unique path that allows us to locate the object in Active Directory):<\/P><PRE class=\"codeSample\">LDAP:\/\/cn=FinAdmins, ou=Finance, dc=fabrikam, dc=com\n<\/PRE>\n<P>Notice that the CN for the group is FinAdmins. We\u2019d <I>like<\/I> the CN for the group to be Finance Managers; in other words, we\u2019d like the ADsPath for the object to look like this:<\/P><PRE class=\"codeSample\">LDAP:\/\/cn=Finance Managers, ou=Finance, dc=fabrikam, dc=com\n<\/PRE>\n<P>We know what you\u2019re thinking, but Active Directory won\u2019t let us directly change the value of the CN attribute; that is, we can\u2019t use code like this to change the CN:<\/P><PRE class=\"codeSample\">objGroup.CN = &#8220;Finance Managers&#8221;\nobjGroup.SetInfo\n<\/PRE>\n<P>But that\u2019s all right; we\u2019ll just \u201cmove\u201d the group. The group started out with this ADsPath:<\/P><PRE class=\"codeSample\">LDAP:\/\/cn=FinAdmins, ou=Finance, dc=fabrikam, dc=com\n<\/PRE>\n<P>Now we\u2019re going to move it to <I>this<\/I> ADsPath:<\/P><PRE class=\"codeSample\">LDAP:\/\/cn=Finance Managers, ou=Finance, dc=fabrikam, dc=com\n<\/PRE>\n<P>The group will still be in the Finance OU, and it will still have all its existing properties and members; it\u2019s the same group, it just has a new ADsPath, and a new CN. Yes, it\u2019s a little weird, but, hey, it works. And it\u2019s no different than using the Move command to rename a file. If you type this from the command prompt, it will rename the file C:\\Logs\\New.log to C:\\Logs\\Old.log:<\/P><PRE class=\"codeSample\">move c:\\logs\\new.log c:\\logs\\old.log\n<\/PRE>\n<P>Same idea.<\/P>\n<P>So what does the code actually look like to rename the group? It looks an awful lot like this:<\/P><PRE class=\"codeSample\">Set objDomain = GetObject(&#8220;LDAP:\/\/ou=finance, dc=fabrikam, dc=com&#8221;)\nobjDomain.MoveHere _\n     &#8220;LDAP:\/\/cn=FinAdmins,ou=Finance,dc=fabrikam,dc=com&#8221;, &#8220;cn=Finance Managers&#8221;\n<\/PRE>\n<P>Like we said, pretty easy. We bind to the Finance OU (the container where the group account resides), and then call the MoveHere method. We need to pass MoveHere two parameters: the ADsPath to the object we want to rename (LDAP:\/\/cn=FinAdmins,ou=Finance,dc=fabrikam,dc=com) , and then new CN for the object (cn=Finance Managers). That\u2019s it. Run the script, and the group will be renamed.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I rename an Active Directory group?&#8212; CL Hey, CL. This is actually pretty easy; as you\u2019ll see, it only takes two lines of code. It\u2019s not a hard problem, it\u2019s just a little bit tricky. That\u2019s because ADSI (at least when it comes to dealing with Active Directory) does not [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,44,3,5],"class_list":["post-70813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-groups","tag-scripting-guy","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I rename an Active Directory group?&#8212; CL Hey, CL. This is actually pretty easy; as you\u2019ll see, it only takes two lines of code. It\u2019s not a hard problem, it\u2019s just a little bit tricky. That\u2019s because ADSI (at least when it comes to dealing with Active Directory) does not [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=70813"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70813\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=70813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}