{"id":68293,"date":"2005-12-20T11:46:00","date_gmt":"2005-12-20T11:46:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/12\/20\/how-can-i-get-the-grandparent-of-an-object-in-active-directory\/"},"modified":"2005-12-20T11:46:00","modified_gmt":"2005-12-20T11:46:00","slug":"how-can-i-get-the-grandparent-of-an-object-in-active-directory","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-get-the-grandparent-of-an-object-in-active-directory\/","title":{"rendered":"How Can I Get the \u201cGrandparent\u201d of an Object in Active Directory?"},"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 get the \u201cgrandparent\u201d of an object in Active Directory?<BR><BR>&#8212; JG<\/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, JG. Wait a second: is this \u201cgrandparent\u201d thing some sneaky reference to the fact that the Scripting Guys (well, except for Jean, of course) are all starting to show their age a bit? OK; we just wanted to make sure. <I>(Editor\u2019s Note: Yes, that originally said \u201cexcept for Greg,\u201d but it\u2019s the editor\u2019s job to keep these articles accurate\u2026.)<\/I><\/P>\n<TABLE id=\"E2C\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. It\u2019s not that the Scripting Guys (well, except for <I>Jean<\/I>, of course) <I>aren\u2019t<\/I> getting old; it just doesn\u2019t seem very sporting to rub it in. Although at their age they probably won\u2019t remember what was said about them anyway.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Actually, what JG is referring to is this. Suppose we have an Active Directory object with the following ADsPath:<\/P><PRE class=\"codeSample\">LDAP:\/\/cn=ken myer, ou=finance, dc=fabrikam, dc=com\n<\/PRE>\n<P>In this case, the Ken Myer user account can be found in the Finance OU; that makes the Finance OU the parent object for this account. Meanwhile, the Finance OU can be found in fabrikam.com; that makes fabrikam.com the parent object for the Finance OU. And because the parent of a parent is a grandparent, fabrikam.com is also the grandparent of the Ken Myer user account.<\/P>\n<TABLE id=\"EPD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P><B>Interesting historical fact<\/B>. National Grandparents Day falls each year on the first Sunday after Labor Day. This holiday was started by a married couple that had 40 grandchildren. The Scripting Guys fully support the idea of a Grandparents Day; after all, who could be more deserving? Still, we find it interesting that Grandparents Day was started by a couple who would then be eligible to receive 40 additional gifts each and every year.<\/P>\n<P>Say, did we mention that January 11<SUP>th<\/SUP> is Scripting Guys Day\u2026?<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Here\u2019s a script that can determine the grandparent for an Active Directory object:<\/P><PRE class=\"codeSample\">Set objUser = GetObject(&#8220;LDAP:\/\/cn=ken myer, ou=finance, dc=fabrikam, dc=com&#8221;)\nSet objParent = GetObject(objUser.Parent)\nWscript.Echo &#8220;Grandparent: &#8221; &amp; objParent.Parent\n<\/PRE>\n<P>That\u2019s right: this is <I>very<\/I> easy. That\u2019s because Active Directory objects all have a <B>Parent <\/B>attribute that returns the ADsPath to the parent object. That\u2019s the secret to determining the grandparent of an object. The script begins by binding to the Ken Myer account in Active Directory. We then encounter this line of code:<\/P><PRE class=\"codeSample\">Set objParent = GetObject(objUser.Parent)\n<\/PRE>\n<P>All we\u2019re doing here is binding to the parent object for the Ken Myer account (objUser.Parent). As we noted, the Parent attribute returns the ADsPath for the parent object; in this case, that\u2019s <B>LDAP:\/\/ou=finance, dc=fabrikam, dc=com<\/B>. After we\u2019ve made a connection to the Finance OU we can then echo back the value of <I>its<\/I> Parent attribute:<\/P><PRE class=\"codeSample\">Wscript.Echo &#8220;Grandparent: &#8221; &amp; objParent.Parent\n<\/PRE>\n<P>As we noted, the parent of the parent will be the grandparent of the Ken Myer account. <\/P>\n<P>Hey, no need to thanks us. Just be sure to mark January 11th on your calendar and we\u2019ll call it good.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I get the \u201cgrandparent\u201d of an object in Active Directory?&#8212; JG Hey, JG. Wait a second: is this \u201cgrandparent\u201d thing some sneaky reference to the fact that the Scripting Guys (well, except for Jean, of course) are all starting to show their age a bit? OK; we just wanted to [&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":[9,3,4,5],"class_list":["post-68293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-adsi","tag-scripting-guy","tag-scripting-techniques","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I get the \u201cgrandparent\u201d of an object in Active Directory?&#8212; JG Hey, JG. Wait a second: is this \u201cgrandparent\u201d thing some sneaky reference to the fact that the Scripting Guys (well, except for Jean, of course) are all starting to show their age a bit? OK; we just wanted to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68293","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=68293"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/68293\/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=68293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=68293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=68293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}