FANDOM



Sub EnumOUs(sADsPath)
    Dim oContainer As Object
    Set oContainer = GetObject(sADsPath)
    oContainer.Filter = Array("OrganizationalUnit")
    Dim oOU As Object
    For Each oOU In oContainer
        Debug.Print oOU.ADsPath
        EnumUsers (oOU.ADsPath)
        EnumOUs (oOU.ADsPath)
    Next

End Sub

Sub EnumUsers(sADsPath)
    Dim oContainer As Object
    Set oContainer = GetObject(sADsPath)
    oContainer.Filter = Array("User")
    Dim oADobject As Object ' as IADsUser
    For Each oADobject In oContainer
        If Len(Trim(oADobject.Description)) > 0 Then
           
            If LCase(oADobject.Class) = "user" Then
               
                On Error Resume Next
                Dim s As String: s = LCase(oADobject.LastName)
                On Error GoTo 0

                Dim u As Collection: Set u = New Collection
               
                On Error Resume Next
                s = "": s = oADobject.sAMAccountName: u.Add s, "sAMAccountName"
                s = "": s = oADobject.DisplayName: u.Add s, "DisplayName"
                s = "": s = oADobject.TelephoneMobile: u.Add s, "TelephoneMobile"
                s = "": s = oADobject.TelephoneNumber: u.Add s, "TelephoneNumber"
                s = "": s = oADobject.LastLogin: u.Add s, "LastLogin"
                s = "": s = oADobject.Manager: u.Add s, "Manager"
                On Error GoTo 0
               
            End If
        End If

    Next

End Sub


Sub ListUsers()
    Dim oDomain As Object
    Set oDomain = GetObject("LDAP://" & GetObject("LDAP://RootDSE").Get("DefaultNamingContext"))
   
    Call EnumOUs(oDomain.ADsPath)
End Sub

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.