Hi,
I am producing a report with User account information from LDAP. Someone asked my adding Account expires, lastlogon and lastlogontimestamp. It is a quite old script . So I extracted the failing part.
It is failing with
.Cells(x, 11).Value = Ouser.accountExpires
.Cells(x, 12).Value = Ouser.lastlogon
.Cells(x, 13).Value = Ouser.lastlogonTimeStamp
So what would be the solution?
I am producing a report with User account information from LDAP. Someone asked my adding Account expires, lastlogon and lastlogontimestamp. It is a quite old script . So I extracted the failing part.
It is failing with
.Cells(x, 11).Value = Ouser.accountExpires
.Cells(x, 12).Value = Ouser.lastlogon
.Cells(x, 13).Value = Ouser.lastlogonTimeStamp
VBA Code:
Dim oRoot
Set oRoot = GetObject("LDAP://rootDSE")
Dim sDomain
sDomain = oRoot.get("defaultNamingContext")
Dim strLDAP
strLDAP = "LDAP://" & sDomain
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") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT adsPath FROM '" & strLDAP & "' WHERE objectCategory='person'AND objectClass='user'"
Set objRecordSet = objCommand.Execute
x = 2
Set sht = ThisWorkbook.Worksheets(Arr_FeuilAD(2))
With sht
Do Until objRecordSet.EOF
Set Ouser = GetObject(objRecordSet.Fields("aDSPath"))
skip = Ouser.sAMAccountName
'disa = Ouser.Account 'disabled
If (skip = "administrateur")
Then
'.Cells(x, 1).Value = "test"
DoEvents
objRecordSet.MoveNext
Else
Application.StatusBar = x & " " & Ouser.DisplayName
.Cells(x, 1).Value = Ouser.ipPhone
.Cells(x, 2).Value = CStr(Ouser.sAMAccountName) 'Replace(oUser.Name, "CN=", "")
.Cells(x, 3).Value = Ouser.givenName
.Cells(x, 4).Value = Ouser.SN
.Cells(x, 5).Value = Ouser.DisplayName
.Cells(x, 6).Value = Ouser.department
.Cells(x, 7).Value = Ouser.distinguishedName
.Cells(x, 10).Value = Ouser.mail
.Cells(x, 11).Value = Ouser.accountExpires
.Cells(x, 12).Value = Ouser.lastlogon
.Cells(x, 13).Value = Ouser.lastlogonTimeStamp
'.Cells(x, 8).Value = oUser.initials
'.Cells(x, 8).Value = oUser.ipPhone
'.Cells(x, 8).Value = oUser.mobile
'.Cells(x, 9).Value = oUser.facsimileTelephoneNumber
'.Cells(x, 10).Value = oUser.initials
'.Cells(x, 11).Value = oUser.company
'.Cells(x, 12).Value = oUser.streetAddress
'.Cells(x, 13).Value = oUser.postOfficeBox
'.Cells(x, 14).Value = oUser.postalCode
'.Cells(x, 15).Value = oUser.l ' by
'.Cells(x, 16).Value = oUser.st
DoEvents
x = x + 1
objRecordSet.MoveNext
End If
Loop
End With
Range("A1:E1").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.AutoFilter
Range("A1").Select
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
So what would be the solution?