Dim objConnection : Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Dim objCommand : Set objCommand = Createobject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
' *** Please correct the path below ***
objCommand.CommandText = ";" & _
"(&(objectClass=user)(objectCategory=person)(extensionAttribute1=*));" & _
"name,title,distinguishedName,extensionAttribute1;subtree"
Dim objRecordSet : Set objRecordSet = objCommand.Execute
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile("BackupFile.csv", 2, True, 0)
Do Until objRecordSet.EOF
Dim strExtAttr1 : strExtAttr1 = objRecordSet.Fields("extensionAttribute1").Value
Dim strTitle
If Not IsNull(objRecordSet.Fields("title")) Then
strTitle = objRecordSet.Fields("title").Value
Else
strTitle = ""
End If
objFile.WriteLine objRecordSet.Fields("distinguishedName").Value & vbTab & _
objRecordSet.Fields("name").Value & vbTab & strTitle & vbTab & strExtAttr1
Dim objUser : Set objUser = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value)
' Add the value to title
objUser.Put "title", strExtAttr1
' This clears the value from extensionAttribute1
objUser.PutEx 1, "extensionAttribute1", 0
objUser.SetInfo
objRecordSet.MoveNext
Loop
|