Extraction attribut LDAP multi value en VBS
Bonjour,
J'ai écris ce code qui permet d'extraire des données depuis un LDAP. Je bloque sur un attribut multi value ("value"), lors de l'extraction je reçois qu'une seule entrée.
J'ai tenté d'utiliser un tableau pour enregistrer les valeurs mais j'ai un erreur d'exécution '91'.
Quelqu'un aurait une idée ? Je ne suis pas expert en VBS...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
Sub Extract()
Dim objConnection, objCommand, objRecordSet, objFSO, objF
Dim sName, sDisplay, strPath, strName, listGroups, StrTmp
Const ADS_SCOPE_SUBTREE = 2
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
strName = "output.csv"
strPath = ".\"
If (objFSO.FileExists(strPath & strName)) Then
objFSO.DeleteFile strPath & strName
End If
Set objF = objFSO.CreateTextFile(strPath & strName)
objF.Close
Set objF = objFSO.openTextFile(strPath & strName, ForAppending)
sUser = "admin"
sDN = "cn=" & sUser & ",dc=company,dc=com"
sRoot = "LDAP://127.0.0.1:1389/dc=company,dc=com"
Dim oDS: Set oDS = GetObject("LDAP:")
Dim oAuth: Set oAuth = oDS.OpenDSObject(sRoot, sDN, "password", 0)
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider", sDN, "password"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT value, uid, displayName FROM 'LDAP://127.0.0.1:1389/OU=security,dc=company,dc=com'" & "WHERE objectClass='provisioningvalues' AND uid='1576*' OR objectClass='rules' AND uid='1576*'"
Set objRecordSet = objCommand.Execute
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
sName = objRecordSet.Fields("uid").Value
sDisplay = objRecordSet.Fields("displayName").Value
'On stocke l'ensemble des groupes dans un tableau de variants
listGroups = objRecordSet.Fields("value").Value
'Pour chaque élément du tableau
For i = LBound(listGroups) To UBound(listGroups)
objF.WriteLine (sName & ";" & i & ";" & sDisplay)
Next i
objRecordSet.MoveNext
objF.Close
Loop
End Sub |