Page 1 of 1 1
Topic Options
#141816 - 2005-06-16 04:11 PM AD Scripting Tutoral
Chris S. Offline
MM club member
*****

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.

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
#141817 - 2006-02-18 02:55 AM Re: AD Scripting Tutoral
therob Offline
Starting to like KiXtart

Registered: 2005-05-19
Posts: 150
Loc: Frankfurt/M., Germany
This helped me a lot. Thank you!
_________________________
Eternity is a long time, especially towards the end. - W.Allan

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 503 anonymous users online.
Newest Members
Timothy, Jojo67, MaikSimon, kvn317, kixtarts2025
17874 Registered Users

Generated in 0.041 seconds in which 0.021 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org