Manipulating Extension Attributes with ADSI
Manipulating Extension Attributes with ADSI
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.
Visual Basic
' Description: Manipulating Extension Attributes with ADSI ' ' This sample demonstrates how to query for ' mail-enabled User objects that do not have the extensionattribute2 ' property set and to set it on the User object. ' ' Visual Basic Project References ' - Microsoft ActiveX Data Objects 2.5 Library ' - Active DS Type Library Sub Main() Dim oRootDSE As IADs Dim objUser As IADsUser Dim oConnection As New ADODB.Connection Dim oCommand As New ADODB.Command Dim RS As ADODB.Recordset Dim strQuery As String, newattrib As String Dim varDomainNC As Variant On Error Resume Next ' Get the configuration naming context. Set oRootDSE = GetObject("LDAP://RootDSE") varDomainNC = oRootDSE.Get("defaultNamingContext") ' Open the connection. oConnection.Provider = "ADsDSOObject" oConnection.Open "ADs Provider" ' Build a query to find all mail-enabled users that do not have ' extensionattribute2 set. strQuery = "<LDAP://" & varDomainNC & ">;(&(&(objectClass=user)(!(extensionAttribute2=*)))((mail=*)));adspath,cn;subtree" oCommand.ActiveConnection = oConnection oCommand.CommandText = strQuery Set RS = oCommand.Execute If RS.RecordCount = 0 Then Debug.Print "No mailbox-enabled user found that does not have extensionattribute2 set" Else While Not RS.EOF Set objUser = GetObject(RS.Fields("adspath")) Debug.Print objUser.cn, "Does not have extensionattribute2 set" ' Set extensionattribute2 to a Social Security number. newattrib = "111-11-1111" objUser.Put "extensionAttribute2", newattrib objUser.SetInfo RS.MoveNext Wend End If Set oRootDSE = Nothing Set objUser = Nothing RS.Close Set RS = Nothing End Sub
Send us your feedback about the Microsoft Exchange Server 2003 SDK.
Build: June 2007 (2007.618.1)
© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.