Modifying an OU






Modifying an OU

Problem

You want to modify one or more attributes of an OU.

Solution

The following examples set the description (description) attribute for the Finance Organizational Unit.

Using a graphical user interface
  1. Open ADSI Edit.

  2. If an entry for the naming context you want to browse is not already displayed, do the following:

    1. Right-click on ADSI Edit in the right pane and click "Connect to.…"

    2. Fill in the information for the naming context, container, or OU you want to add an object to. Click on the Advanced button if you need to enter alternate credentials.

  3. In the left pane, browse to the container or OU that contains the object you want to modify. Once you've found the object, right-click on it and select Properties.

  4. Right-click the description attribute and select Edit.

  5. Enter Finance Department and click OK.

  6. Click Apply, followed by OK.

Using a command-line interface

To modify an object using AdMod, you'll use the following general syntax:

	> admod b <ObjectDN> <attribute>:<operation>:<value>

For example, you can add a description to an OU object using the following syntax:

	> admod -b cn="ou=Finance,dc=rallencorp,dc=com"
	   description::"Finance Department"

You can modify a limited number of object types with DSMod. Run dsmod /? from a command line for more details.

Using VBScript
	strObjectDN = "ou=Finance,dc=rallencorp,dc=com"
	set objUser = GetObject("LDAP://" & strObjectDN)
	objUser.Put "description", "Finance Department"
	objUser.SetInfo

Discussion

Modifying the attributes of an OU is a relatively straightforward process that's similar to modifying other types of objects within Active Directory. You can modify most attributes of an OU using the Active Directory Computers and Users MMC snap-in, but some attributes will be available for editing only by using ADSI Edit or a command-line or scripting utility.

Using VBScript

To simply view some common properties of an OU, use the following code:

	strOUDN = ou="<OU DN>" ' i.e. "ou=Finance,dc=rallencorp,dc=com"
	Set objContainer = GetObject("LDAP://" & strOUDN)

	For Each strValue in objContainer.description
	  WScript.Echo "Description: " & strValue
	Next

	Wscript.Echo "Street Address: " & strStreetAddress
	Wscript.Echo "Province/State: " & objContainer.st
	Wscript.Echo "Postal/ZIP Code: " & objContainer.postalCode
	Wscript.Echo " 
Country: " & objContainer.c

To clear a property of an OU, you need to use the PutEx method in combination with the ADS_PROPERTY_CLEAR value, as follows:

	Const ADS_PROPERTY_CLEAR = 1
	strOUDN = ou="<OU DN>" ' i.e. "ou=Finance,dc=rallencorp,dc=com"

	Set objContainer = GetObject("LDAP://" & strOUDN)

	objContainer.PutEx ADS_PROPERTY_CLEAR, "description", 0
	objContainer.PutEx ADS_PROPERTY_CLEAR, "street", 0
	objContainer.PutEx ADS_PROPERTY_CLEAR, "st", 0
	objContainer.PutEx ADS_PROPERTY_CLEAR, "postalCode", 0
	objContainer.PutEx ADS_PROPERTY_CLEAR, "c", 0
	objContainer.SetInfo

See Also

MSDN: IADs::Put, MSDN: IADs::PutEx, MSDN: IADs::SetInfo, and MSDN: ADS_ PROPERTY_OPERATION_ENUM



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows