O'Reilly logo

Active Directory Cookbook by Robbie Allen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.11. Indexing an Attribute

Problem

You want to index an attribute so that searches using that attribute are faster.

Solution

Tip

For Windows 2000 Active Directory you need to enable schema modifications before proceeding. See Recipe 10.2 for more information.

Using a graphical user interface

  1. Open the Active Directory Schema snap-in.

  2. In the left pane, click on the Attributes folder.

  3. In the right pane, double-click the attribute you want to index.

  4. Check the box beside Index this attribute in the Active Directory.

  5. Click OK.

Using a command-line interface

You can index an attribute by using the ldifde utility and an LDIF file that contains the following:

dn: cn=<AttrCommonName>,cn=schema,cn=configuration,<ForestRootDN>
changetype: modify
replace: searchFlags
searchFlags: 1
-

If the LDIF file were named index_attribute.ldf, you would run the following command:

> ldifde -v -i -f index_attribute.ldf

Using VBScript

' This code indexes an attribute.
' ------ SCRIPT CONFIGURATION ------
' Set to the common name (not LDAP display name) of the attribute
strAttrName = "<AttrCommonName>"   ' e.g. rallencorp-LanguagesSpoken
' ------ END CONFIGURATION ---------

set objRootDSE = GetObject("LDAP://RootDSE")
set objAttr = GetObject("LDAP://cn=" & strAttrName & "," &
                        objRootDSE.Get("schemaNamingContext"))
objAttr.Put "searchFlags", 1
objAttr.SetInfo
WScript.Echo "Indexed attribute: " & strAttrName

Tip

The CLI and VBScript solutions assume that searchFlags wasn’t previously set and just blindly overwrites whatever ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required