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
|
On Error Resume Next
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") = 2000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objExcel = CreateObject("Excel.Application")
Set ObjFso = CreateObject("Scripting.FileSystemObject")
objExcel.Visible = True
objExcel.Workbooks.Add()
SiteOpt = "Ou=Users,Ou=Site, Ou=Location,dc=fabrikam,dc=com"
objExcel.Cells(1, 1).Value = "Liste des Comptes dont le compte n'expire jamais, le " & FormatDateTime(Now, vbLongDate)
objExcel.Cells(1, 1).Font.Bold = True
objExcel.Cells(1, 1).Font.Size = 10
objExcel.Cells(1, 1).Font.ColorIndex = 3
' Ajout des titres de colonnes
objExcel.Cells(3, 2).Value = "distinguishedName"
objExcel.Cells(3, 2).Font.ColorIndex = 5
objExcel.Cells(3, 3).Value = "department"
objExcel.Cells(3, 3).Font.ColorIndex = 5
objExcel.Cells(3, 4).Value = "name"
objExcel.Cells(3, 4).Font.ColorIndex = 5
objExcel.Cells(3, 5).Value = "displayName"
objExcel.Cells(3, 5).Font.ColorIndex = 5
objExcel.Cells(3, 6).Value = "AccountExpirationDate"
objExcel.Cells(3, 6).Font.ColorIndex = 5
x = 4
objCommand.CommandText = "SELECT AdsPath FROM 'LDAP://" & SiteOpt & "WHERE objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Set objUser = GetObject(objRecordSet.Fields("AdsPath").Value)
objExcel.Cells(x, 2).Value = objUser.distinguishedName
objExcel.Cells(x, 3).Value = objUser.department
objExcel.Cells(x, 4).Value = objUser.name
objExcel.Cells(x, 5).Value = objUser.displayName
dtmAccountExpiration = objUser.AccountExpirationDate
If Err.Number = -2147467259 Or Instr(dtmAccountExpiration, "1970") > 0 Or Instr(dtmAccountExpiration, "1601") > 0 Then
objExcel.Cells(x, 6).Value = "This account has no expiration date."
Else
objExcel.Cells(x, 6).Value = "Account expiration date: " & objUser.AccountExpirationDate
End If
x = x + 1
objRecordSet.MoveNext
Loop
objExcel.Cells(x, 1).Value = x-4 & " entries found"
x= x + 1
objExcel.Cells(x, 1).Value = "***** End of list *****"
objExcel.Cells(x, 1).Font.Bold = True
objExcel.Cells(x, 1).Font.Size = 10
objExcel.Cells(x, 1).Font.ColorIndex = 3 |