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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
| 'On Error Resume Next
' Variables
Const ADS_GROUP_TYPE_BUILTIN = &H1
Const ADS_GROUP_TYPE_GLOBAL = &H2
Const ADS_GROUP_TYPE_LOCAL = &H4
Const ADS_GROUP_TYPE_UNIVERSAL = &H8
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000
Const ADS_UF_ACCOUNTDISABLE = 2
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
dim nb_ou
dim ou()
dim ou_lib()
' ********************************************************************************
' * Vérification des paramètres
' ********************************************************************************
Set objArgs = WScript.Arguments
Affiuser=1
StrOURecherche="OU=test"
FichierResultats="traceruser.txt"
' ********************************************************************************
' * Connexion a l'AD
' ********************************************************************************
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(FichierResultats , ForWriting, True)
Set objRootDSE = GetObject("LDAP://RootDSE")
strForest = objRootDSE.Get("rootDomainNamingContext")
Set objForest = GetObject("LDAP://OU=OUParent,OU=MonOu," & strForest )
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set objFSO_A = CreateObject("Scripting.FileSystemObject")
Set objTextFile_A = objFSO_A.OpenTextFile("trace.txt" , ForWriting, True)
Call EnumDomains(objForest)
' ********************************************************************************
' * Fin du Script + fermeture de la connexion AD
' ********************************************************************************
wscript.echo "FIN DE TRAITEMENT"
adoConnection.Close
' ********************************************************************************
' * Enumeration des OU racine au DOMAINE
' ********************************************************************************
Sub EnumDomains(ByVal objParent)
objParent.Filter = Array("organizationalUnit")
For Each objContainer In objParent
if objContainer.Name=StrOURecherche then
Call EnumContainers(objContainer, "")
end if
Next
End Sub
' ********************************************************************************
' * Enumeration des OU
' ********************************************************************************
Sub EnumContainers(ByVal objParent, ByVal strOffset)
objParent.Filter = Array("organizationalUnit")
strManagedBy = objparent.managedby
If IsEmpty(objparent.managedby) = TRUE Then
xw="(Pas de Manager)"
Else
Set objUser = GetObject("LDAP://" & objparent.managedby)
ipphoneX=find_phone(objuser.distinguishedName)
If len(ipphoneX)<>4 then
xw=" Managé par : " & objUser.Get("displayName") & " (Messagerie : " & objUser.Get("mail") & ") (Matricule : " & objUser.Get("employeeNumber") & ")"
else
xw=" Managé par : " & objUser.Get("displayName") & " (Messagerie : " & objUser.Get("mail") & ") (Téléphone : " & ipphoneX &") (Matricule : " & objUser.Get("employeeNumber") & ")"
end if
End If
objTextFile.WriteLine("")
objTextFile.WriteLine(strOffset & " " &right(objParent.Name,len(objParent.Name)-3) & " : " & objParent.Description & xw )
objTextFile_A.WriteLine (objParent.Description)
objTextFile_A.WriteLine ("Organisation : " &right(objParent.Name,len(objParent.Name)-3) & " " & objParent.distinguishedName )
objTextFile_A.WriteLine ("")
objTextFile_A.WriteLine (xw)
objTextFile_A.WriteLine ("")
objTextFile.WriteLine("")
Call ListeUsers(objParent, ";" & strOffset)
objParent.Filter = Array("organizationalUnit")
For Each objChild In objParent
Call EnumContainers(objChild,";" & strOffset)
Next
End Sub
********************************************************************************
' * Listage des Utilisateurs
' ********************************************************************************
Sub ListeUsers(ByVal objContainer, ByVal strOffset)
objContainer.Filter = Array("user")
lngUsers = 0
lngComputers = 0
i=0
For Each objMember In objContainer
If (LCase(objMember.Class) = "user") Then
if Affiuser=1 then
'--------------------------------------------------'
'test si compte désactivé ? et date expiration...
'--------------------------------------------------'
Set bobjConnection = CreateObject("ADODB.Connection")
bobjConnection.Open "Provider=ADsDSOObject;"
Set bobjCommand = CreateObject("ADODB.Command")
bobjCommand.ActiveConnection = bobjConnection
bobjCommand.CommandText = "<LDAP://" & objMember.distinguishedname & ">;(objectCategory=User);distinguishedName,mail,employeeNumber,userAccountControl;subtree"
Set bobjRecordSet = bobjCommand.Execute
intUAC=bobjRecordset.Fields("userAccountControl")
d_mes=""
If intUAC AND ADS_UF_ACCOUNTDISABLE Then
Set wobjUser = GetObject("LDAP://"& bobjRecordset.Fields("distinguishedName"))
dtmAccountExpiration = wobjUser.AccountExpirationDate
If Err.Number = -2147467259 OR dtmAccountExpiration = #1/1/1970# Then
d_mes=" (Compte Désactivé)"
Else
d_mes= " (Compte Désactivé expiré le : " & wobjUser.AccountExpirationDate &")"
End If
End If
bobjConnection.Close
if objMember.ipPhone<>"" then
objTextFile_A.WriteLine (right(objMember.Name,len(objMember.Name)-3) & " (Telephone : " & objMember.ipPhone & ") (Messagerie : " & objMember.mail & ")" & ") (Matricule : " & objMember.employeeNumber & ")" & d_mes )
objTextFile.WriteLine (strOffset & right(objMember.Name,len(objMember.Name)-3) & " (" & objMember.ipPhone & ")" & d_mes )
else
objTextFile_A.WriteLine (right(objMember.Name,len(objMember.Name)-3) &" (Messagerie : " & objMember.mail & ") (Matricule : " & objMember.employeeNumber & ")" &d_mes )
objTextFile.WriteLine (strOffset & right(objMember.Name,len(objMember.Name)-3) &" " &d_mes )
end if
i=i+1
end if
'objTextFile.WriteLine(strOffset & "" & right(objMember.Name,len(objMember.Name)-3))
End If
Next
objTextFile_A.WriteLine ("")
objTextFile_A.WriteLine (i & " agent(s)")
'objTextFile.WriteLine(strOffset & "SAUT PAGE")
objTextFile_A.WriteLine "---------------------------------------------------------------" & chr(10)& chr(13) & chr(10)
End Sub
function find_phone (x)
Set aobjConnection = CreateObject("ADODB.Connection")
aobjConnection.Open "Provider=ADsDSOObject;"
Set aobjCommand = CreateObject("ADODB.Command")
aobjCommand.ActiveConnection = aobjConnection
aobjCommand.CommandText = "<LDAP://" & x & ">;(objectCategory=User);distinguishedName,ipPhone;subtree"
Set aobjRecordSet = aobjCommand.Execute
find_phone=aobjRecordset.Fields("ipPhone")
aobjConnection.Close
end function |
Partager