SUPINFO International University

SUPINFO Institute of Information Technology
Laboratoire Microsoft




Créer une série d'utilisateur (AD)

Accueil > Script > active_directory > Créer une série d'utilisateur (AD)

Créer une série d'utilisateur (AD)

Par Ismaël LIMBADA, LABORATOIRE SUPINFO DES TECHNOLOGIES MICROSOFT
Publiée le 31/05/2006 vers 12h.


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


Proposer un script

Notre avis :

Votre avis :

Réactions :
0

Votants :
8

Visites :
11744

1
2
3
4
5

Scripts Windows Précédent :

Renommer un compte utilisateur (WinXP)



Retrouvez ci-dessous les autres sections du Laboratoire Microsoft