2

I am getting a ADGroup using this code,

        using (var context = Utilities.GetPrincipalContext(OU))
        using (var gpe = new GroupPrincipalExtension(context, "*"))
        using (var ps = new PrincipalSearcher(gpe))
        {
            foreach (var g in ps.FindAll())
            {
                Console.WriteLine(g.DisplayName);
            }
        }

It's giving DisplayName null, because the attribute is available but under another object, here is what I see in LOCAL window when debugging,

enter image description here

Edit

I thought code was self explaining but if it causes confusion, I am trying to get all groups in a specific OU, then trying to get a custom attribute "DisplayName", GroupPrincipalExtension inherits from GroupPrincipal class of system.directoryservices.accountmanagement.

When debugging I can see "g" object has Test.AD.GroupPrincipalExtension (I don't know what to call it ? underline object ? a property ? not sure...) which has DisplayName property.

Because I can't get g.DisplayName, how can i get following,

g.Test.AD.GroupPrincipalExtension.DisplayName
Roy T.
  • 9,429
  • 2
  • 48
  • 70
Mathematics
  • 7,314
  • 25
  • 77
  • 152
  • 1
    I didn't vote yet, but its really not clear what you are asking. What are you trying to do? Have you seen this question? (http://stackoverflow.com/questions/6692767/how-do-i-get-the-ad-display-name-of-the-currently-logged-in-user) does that help you? – Roy T. Sep 22 '15 at 07:16
  • @RoyT. I updated my question to make it more obvious to get an answer – Mathematics Sep 22 '15 at 07:20
  • You should really show your objects structure. – kamil-mrzyglod Sep 22 '15 at 07:22
  • @Kamo I am inheriting from this class - https://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.groupprincipal(v=vs.110).aspx – Mathematics Sep 22 '15 at 07:27

1 Answers1

1

There is no path g.Test.AD.GroupPrincipalExtension.DisplayName. Visual Studio just shows you that g is of type Test.AD.GroupPrincipalExtension (since g is of type Principal).

Since you use gpe as a filter on PrincipalSearcher, the type you see is GroupPrincipalExtension. (Your GroupPrincipalExtension inherits Principal, which is the type PrincipalSearchResult<Principal> enumerates over, as you do in your foreach).

You have to find for the issue somewhere else, maybe in your GroupPrincipalExtension. The call to Principal.DisplayName is okay.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325