| 12
 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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 
 | 
on error resume next
'déclaration des variables (pas obligatoire en VBS)
dim objfichier, Myfile, Ouchoisi
const forReading = 1, ForWriting = 2, ForAppending = 8
'routine de connexion a l'AD
Const ADS_SCOPE_SUBTREE = 2
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 
'choix du domaine a éxaminer
DomaineChoisi=inputbox ("veuillez Choisir le domaine que vous voulez inspecter","Choix du domaine")
DomaineChoisi2=inputbox ("veuillez Choisir la fin du nom de domaine que vous voulez inspecter","Choix du domaine")
OuChoisi=inputbox ("veuillez Choisir l'Unité d'organisation que vous voulez inspecter","Choix de l'OU")
'sélection de l'OU dans le domaine
objCommand.CommandText = _
    "SELECT AdsPath FROM 'LDAP://OU="& OuChoisi &", dc="& DomaineChoisi &", dc="& DomaineChoisi2 &"' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
'création du fichier texte
set objfichier = createobject("scripting.filesystemobject")
NomFichier="export.csv"            '   inputbox ("Veuillez entrez le nom de fichier","Nom du Fichier")
set Myfile = objfichier.opentextfile(NomFichier, ForWriting, true)
'boucle qui vérifie les utilisateurs 1 par 1
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
    Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
  
  'condition, extensionAttribute4 est vide, pas de date d'expiration, et un prénom ( boite nominative )
  
    If objUser.extensionAttribute4 is Empty AND objUser.dtmAccountExpiration = "01/01/1601 01:00:00" AND objUser.givenName <> "" then
		 
	   'si oui, afficher tel et tel informations
	   
	   Myfile.Writeline objUser.cn & ";" & objUser.distinguishedName & ";" & objuser.whenCreated & ";" & objuser.extensionAttribute4
    End If
    objRecordSet.MoveNext
	
Loop
'message de fin d'éxecution du script
MsgBox "votre recherche dans l'AD est terminée", vbExclamation, "Avertissement" | 
Partager