I have found the following thread which ADezii solved very nicely: ...Grab information from AD.... However, this just pulls for the current user. I want to be able to specify the user so that I can get their email address. From research that I have done online (ADSI Active Directory), you must use LDAP and not WinNT to be able to pull the EmailAddress property of the user. Again from looking online, it seems that I need to know the OU where the user is located to be able to do this. The problem is that our users are arranged through many different OUs and I can't predict where via code.
What I'm trying to do is get the email addresses for everyone in a specific security group. I had managed to get several pieces of information using the following code.
Everything in this works except for the adNTUser.EmailA ddress at the end of the Debug.Print line. So I just need to replace the WinNT string with an LDAP string that allows me to search for the user by username. I had tried
but I get an error saying "There is no such object on the server". I don't know much about LDAP and I have no clue what else to try.
What I'm trying to do is get the email addresses for everyone in a specific security group. I had managed to get several pieces of information using the following code.
Code:
Public Sub UsersInGroup(GroupName As String) Dim adGroup As ActiveDs.IADsGroup Dim adMembers As IADsMembers Dim adMember As IADs Dim adNTUser As IADsUser Set adGroup = GetObject("WinNT://MyDomain/" & GroupName) Set adMembers = adGroup.Members For Each adMember In adMembers Set adNTUser = GetObject("WinNT://MyDomain/" & adMember.Name & ",user") Debug.Print adMember.Name, adNTUser.FullName, adNTUser.IsAccountLocked, adNTUser.PasswordExpirationDate, adNTUser.EmailAddress Next End Sub
Code:
"LDAP://CN=" & adNTUser.FullName & ",CN=Users,DC=MyDomain,DC=com"
Comment