Option Explicit
Dim MyDistinguishedName
Dim objRootDSE, objItem, objConnection, objCommand, objRecordSet
Dim strContainer, strname
Dim intCounter
Dim varListeAccounts, varMyAccount, varListeAccountsLDAPFormat, MonObjUser
Dim varDepartment
Const ADS_UF_ACCOUNTDISABLE = 2
Const ADS_SCOPE_SUBTREE = 2
'Liste des comptes à traiter
varListeAccounts = "login1;login2;login3"
'Définition de valeurs que l'on va renseigner dans différents champs des logins
varDepartment = Left("Direction du service Acaht", 64) 'Le champs ne peut pas contenir plus de 64 caractères
Const varDescription = "Ma description"
Const varFonction = "Gestionnaire"
Const varSociete = "Tutos.eu"
Const varManager = "CN=Roberto,CN=Users,DC=MyDomain,DC=Local"
strContainer = "" 'Si vous souhaitez vous connecter à une OU en particulié, indiquez la ici
varListeAccountsLDAPFormat = ""
For Each varMyAccount In Split(varListeAccounts,";")
varListeAccountsLDAPFormat = varListeAccountsLDAPFormat & "(sAMAccountName=" & varMyAccount & ")"
Next
Wscript.echo varListeAccountsLDAPFormat
On Error Resume Next
Set objRootDSE = GetObject("LDAP://rootDSE")
If strContainer = "" Then
Set objItem = GetObject("LDAP://" & objRootDSE.Get("defaultNamingContext"))
Else
Set objItem = GetObject("LDAP://" & strContainer & "," & _
objRootDSE.Get("defaultNamingContext"))
End If
On Error Goto 0
'strname = objItem.Get("name")
'WScript.Echo "name: " & strname
MyDistinguishedName = objItem.Get("distinguishedName") 'Récupération du distinguishedName du domaine par défaut. Exemple DC=Cotonso,DC=Com
'WScript.Echo "distinguishedName: " & MyDistinguishedName
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'objCommand.CommandText = "<LDAP://" & MyDistinguishedName & ">;(&(objectCategory=User)(sAMAccountName=" & varMyAccount & "));name,cn,displayName,sn,mail,mailNickname,sAMAccountName,distinguishedName;subtree"
objCommand.CommandText = "<LDAP://" & MyDistinguishedName & ">;(&(objectCategory=User)(|" & varListeAccountsLDAPFormat & "));name,cn,displayName,sn,sAMAccountName,distinguishedName;subtree"
objCommand.Properties("Page Size") = 10000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
intCounter = 0
Do Until objRecordset.EOF
'WScript.echo objRecordset.Fields("distinguishedName")
WScript.echo "Name : " & VbTab & objRecordset.Fields("Name")
'WScript.echo VbTab & "cn : " & VbTab & objRecordset.Fields("cn")
'WScript.echo VbTab & "displayName : " & VbTab & objRecordset.Fields("displayName")
'WScript.echo VbTab & "sn : " & VbTab & objRecordset.Fields("sn")
WScript.echo VbTab & "sAMAccountName : " & VbTab & objRecordset.Fields("sAMAccountName")
WScript.echo VbTab & "distinguishedName : " & VbTab & objRecordset.Fields("distinguishedName")
Set MonObjUser = GetObject("LDAP://" & objRecordset.Fields("distinguishedName"))
MonObjUser.Put "Description", varDescription
MonObjUser.Put "title", varFonction
MonObjUser.Put "Company", varSociete
MonObjUser.Put "department", varDepartment
MonObjUser.Put "manager", varManager
MonObjUser.SetInfo
Set MonObjUser = Nothing
objRecordset.MoveNext
Loop
objConnection.Close
Lien vers le fichier : cliquez ici
Article(s) suivant(s)
Article(s) précédent(s)
Article(s) en relation(s)