De TeteveWiki.
Connexions avec login/password en "GetObject"
Connexion à AD
Sub main()
Dim DSO, oDSO, oUser
Dim mail, newmail
Dim DnName
Const ADS_SECURE_AUTHENTICATION = &H1
Const ADS_SERVER_BIND = &H200
DnName = "cn=Utilisateur,ou=Users,dc=domaine,dc=fr"
Set dso = GetObject("LDAP:")
Set oDSO = dso.OpenDSObject("LDAP://" & DnName, "domaine\login", "password", ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)
mail = oUser.EmailAddress
newmail = Replace(mail, "domaine.fr", "vide.fr")
oUser.Put "Mail", newmail
oUser.SetInfo
End Sub
Connexion à ADAM
Sub main()
Dim DSO, objGrp, element, pathperson
Const ADS_SECURE_AUTHENTICATION = &H1
pathperson = "LDAP://serveur.domaine.tld:port-eventuel/CN=NomGroupe,CN=OU,O=ORGANISATION"
Set DSO = GetObject("LDAP:")
Set objGrp = DSO.OpenDSObject(pathperson, "domaine.tld\user", "password", ADS_SECURE_AUTHENTICATION)
'MsgBox objUser.Get("diag-profilApplicatif")
For Each element In objGrp.Members
If element.Class = "diag-personne" Then
MsgBox element.uid
End If
Next
Set DSO = Nothing
Set objGrp = Nothing
End Sub
Connexions avec login/password et une requête LDAP
Connexion à AD
Sub descri()
Const ADS_SCOPE_SUBTREE = 2
Dim objConnection, objCommand, objRecordSet, stru, descri
usr = "Teteve Vinc"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties("User ID") = "CN=Teteve,OU=USERS,OU=INFRA,DC=DOMAINE,DC=tld"
objConnection.Properties("Password") = "MOTDEPASSETOPSECRETDEFENSE"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT * FROM 'LDAP://domaine.tld/DC=domaine,DC=tld' WHERE Name = '" & usr & "'"
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
MsgBox "Any result"
Else
descri = objRecordSet(0)
End If
MsgBox descri
End Sub
Connexion à ADAM