#141816 - 2005-06-16 04:11 PM
AD Scripting Tutoral
|
Chris S.
MM club member
![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif) ![*](/forums/images/general/default/star.gif)
Registered: 2002-03-18
Posts: 2368
Loc: Earth
|
The following script is a short tutoral demonstrating how to use rootDSE to bind to Active Directory objects. Learning how to connect to Active Directory objects is the basis for all Active Directory scripting.
I hope to have time to create additional tutorals, so we'll call this Lesson One. ![](/ubbthreads/images/graemlins/smile.gif)
If you wish to ask questions regarding this tutoral, or future tutorals, please do so by creating a new post. I will add any relevant information to this post as needed.
Break On $nul=SetOption("WrapAtEOL","On") Color w+/n "=== RootDSE Tutorial =================================================" ? Color w/n "Each directory server has a unique entry called RootDSE. It provides " ? "data about the server, such as its capabilities, the LDAP version it " ? "supports, and the naming contexts it uses."? ? "For example, to create a script, or application, that can run on any " ? "Windows 2000 domain environment. You can specify either the distinguished " ? "name, server name, or domain name when connecting to Active Directory. " ? "If you do not have this information, you can then use the RootDSE object " ? "to establish a connection. The following code example displays the Default " ? "Naming Context for your domain:"? ? Color w+/n '$sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")'? '"RootDSE for this domain is: " + $sADsPath ?'?? Color w/n Color m+/n "Press any key to run the example..." Get $ ?? Color w/n Color w+/n $sADsPath = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext") "RootDSE for this domain is: " + $sADsPath ?? Color w/n Color m+/n "More..." Get $ ?? Color w/n "Now that we have the Default Naming Context in $$sADsPath, we can use it to " ? 'bind to your domain. This is called "Serverless Binding."' ?? Color w+/n '$objDomain = GetObject($$sADsPath)' ?? Color w/n $objDomain = GetObject($sADsPath) Color m+/n "More..." Get $ ?? Color w/n "Ok. We've found the Default Naming Context and used it to bind to your domain. " ?? "Now what?" ?? "Let's use our newly created domain object to enumerate your root Containers " ? "and Organizational Units." ?? "By constructing a For..Next loop using the $$objDomain we can list each object " ? "in the root of your domain (these should only be Organizational Units (OU's) " ? "and Containers (CN's)). Example..." ?? Color w+/n '"Objects in " + $$objDomain.ADsPath ??' ? 'For Each $$objContainer in $$objDomain' ? ' $$objContainer.Name ?' ? 'Next' ?? Color w/n Color m+/n "Press any key to run the example..." Get $ ?? Color w/n Color w+/n "Objects in " + $objDomain.ADsPath ?? For Each $objContainer in $objDomain $objContainer.Name ? Next Color w/n Color m+/n ? "Press any key to end the tutorial." Get $ ?? Color w/n Exit For Each $objContainer in $objDomain ? "*** "+$objContainer.Name+" ***" ? For Each $obj in $objContainer $obj.Name ? Next Get $ Next Get $ Exit $oRootDSE = GetObject("LDAP://rootDSE") "Default Naming Context: " + $oRootDSE.Get(defaultNamingContext) ?? $aNamingContexts = $oRootDSE.Get(namingContexts) "All Naming Contexts:" ? For Each $sNamingContext in $aNamingContexts "+-- " + $sNamingContext ? Next "DS Service Name: " $oRootDSE.Get(dsServiceName) ? Get $ Exit |
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 442 anonymous users online.
|
|
|