0

In Outlook I created a UserForm which gets a User from the domain and display his lastlogon, expiredate, group memberships, etc. But for the group memberships it only displays Security type groups, not distribution type groups of the selected User.

I'm trying to get both (Security and distribution groups) but can't figure out how to do this. Not even with the help of my big friend Google. I'm guessing Objuser.Groups is the problem, but .memberOf or .Members does not seems to work.
What am i doing wrong?

snapshot of the code:

Sub FindUser(Username As String)
Dim objGroup As Object
Dim Objuser As IADsUser

  Set WSHnet = CreateObject("WScript.Network")
  UserDomain = WSHnet.UserDomain

  Set Objuser = GetObject("WinNT://" & UserDomain & "/" & Username & ",user")  

  For Each objGroup In Objuser.Groups
  '!!at this part I only get the Security type groups, not the distribution groups!!

    'Do things with the objGroup
  Next
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Rob
  • 53
  • 1
  • 1
  • 7

1 Answers1

1

WScript.Network has nothing to do with Distribution Groups in Exchange, so that won't be of much help. You need to use the Outlook Object Model - see "Access Exchange User or Distribution List Information from the Address Book".

Eric Legault
  • 5,706
  • 2
  • 22
  • 38
  • Hello Eric, Thank you for your response. Maybe I don't get your anwser, but when I search the same User with Active Directory and check his memberships in the tab "member of" i see among his share's and applications (Security type groups) the distribution lists(Distribution type groups). So my thougt is that I should be able to retrieve the memberships from AD. If not I'll try to get it with your suggestion. But i'm hoping to understand why I see the groups with AD and not when I do it with VBA. – Rob Dec 30 '15 at 07:38
  • Ah, sorry I misunderstood. I believe you'll need to use LDAP, but I can't recall what COM objects are available to do that or whether it is possible with WSH. One .NET approach is discussed here: http://stackoverflow.com/questions/3195617/list-of-users-in-specific-active-directory-distribution-group – Eric Legault Dec 30 '15 at 18:58
  • Tried it with LDAP and now i get all the items that i want. Although it solved my problem i'm still curious why i cannot get it with WinNT. Does someone know why WinNT doesn't give me all the groups and/or what the difference is between WINNT and LDAP? – Rob Jan 05 '16 at 08:50