recuperation de l'extenstionAttribute4 dans un fichier texte
Bonjour,
Ce que je veux faire est assez simple, je veux un script qui fouille une O.U déterminé, et pour les utilisateurs ayant un extensionAttribute4, je veux qu'il me le ressorte dans un fichier texte, avec le mail et le SamAccountName.
Voila le script que j'ai, je pense que c'est la condition qui coince, j'ai déjà essaye pas mal de truc différent pourtant (en code j'ai u niveau bidouilleur lol )
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 58 59 60 61 62 63 64 65 66 67 68 69 70
|
On Error Resume Next
'déclaration des variables
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://CN="& OuChoisi &", dc="& DomaineChoisi &", dc="& DomaineChoisi2 &"' WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
'création du fichier texte
set objfichier = createobject("scripting.filesystemobject")
NomFichier="test.txt" ' 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, y at'il un numéro sirhano'
If extensionAttribute4 <> "0" Then
' MsgBox objUser.extensionAttribute4, vbExclamation, "Avertissement"
'si oui, afficher tel et tel informations
Myfile.Writeline objUser.SamAccountName & ";" & objUser.extensionAttribute4 & ";" & objuser.mail
End If
objRecordSet.MoveNext
Loop
'message de fin d'éxecution du script
MsgBox "votre recherche dans l'AD est terminée", vbExclamation, "Avertissement" |
Merci d'avance