On Error Resume
Next
Const ADS_SCOPE_SUBTREE = 2
strName = "
Utilsateur-"
strSearchName = strName & "*"
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = _
"SELECT AdsPath FROM 'LDAP://
dc=VotreDomaine,dc=com'
WHERE objectCategory='user' " & _
"AND samAccountName = '" & strSearchName & "'"
Set objRecordSet = objCommand.Execute
intRecordCount = objRecordset.RecordCount
intRecordCount = intRecordCount + 1
If intRecordCount < 10 Then
strNewName = strName & "0" & intRecordCount
Else
strNewName = strName & intRecordCount
End If
Set objOU = GetObject("LDAP://
OU=Votre OU,dc=VotreDomaine,dc=com")
Set objUser = objOU.Create("User", "cn= " & strNewName)
objUser.samAccountName = strNewName
objUser.SetInfo
objUser.SetPassword "
password"
objUser.AccountDisabled = False
objUser.SetInfo