Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4623996
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:04:03+00:00 2026-05-22T03:04:03+00:00

I am enumerating a Domain Local Group in Active Directory using: Dim de As

  • 0

I am enumerating a Domain Local Group in Active Directory using:

Dim de As New DirectoryEntry("path")
Dim members As IADsMembers = DirectCast(de.Invoke("Members"), IADsMembers)

members.Filter = New Object() {"user"}
'Iterate over users.
members.Filter = New Object() {"group"}
'Iterate over nested groups.

The Domain Local Group is not enumerating. I have checked members.Count which equals 1.

Having looked in Active Directory there is a Foreign Security Principal which links to a Global Group in another domain. Research suggests that the only options for members.Filter are user and group, user and group.

How can I extract the Foreign Security Principal from this collection?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:04:04+00:00Added an answer on May 22, 2026 at 3:04 am

    For the most part I have chosen to use the functionality provided by System.Directory.AccountManagement in .NET 3.5 to enumerate a global group. If the object being enumerated is actually a Foreign Security Principal then the .NET 3.5 code does not suffice. Hopefully the following code will help someone else:

    Private Sub EnumerateGlobalGroup(ByVal distinguishedName As String)
    
        Try
    
            Using context As New PrincipalContext(ContextType.Domain, GetDomainName(distinguishedName))
                Using gp As GroupPrincipal = GroupPrincipal.FindByIdentity(context, IdentityType.DistinguishedName, distinguishedName)
                    Dim groupMembers As PrincipalSearchResult(Of Principal) = gp.GetMembers(True)
                    For Each member As Principal In groupMembers
    
                        Console.WriteLine(member.DisplayName)
                        Select Case member.StructuralObjectClass
                            Case "user"
                                Console.WriteLine("user")
                            Case "group"
                                Console.WriteLine("group")
                        End Select
    
                    Next
                End Using
            End Using
    
        Catch ex As Exception
    
            If Not TypeOf ex Is PrincipalOperationException Then Throw ex
    
            'Get this far then enumerating Foreign Security Principal.
            Dim groupEntry As New DirectoryEntry("LDAP://" & distinguishedName)
            Dim members As Object = groupEntry.Invoke("Members")
            For Each member As Object In CType(members, IEnumerable)
                Dim memberEntry As New DirectoryEntry(member)
                Console.WriteLine(memberEntry.Name)
    
                Dim sid As New SecurityIdentifier(DirectCast(memberEntry.InvokeGet("objectSid"), Byte()), 0)
                Dim account As NTAccount = sid.Translate(GetType(NTAccount))
                Console.WriteLine(account.ToString)
    
                Dim memberDistinguishedName As String = GetDistinguishedName(account.ToString)
                EnumerateGlobalGroup(memberDistinguishedName)
            Next
    
        End Try
    
    End Sub
    
    Private Function GetDomainName(ByVal dn As String) As String
    
        Dim dnParts As String() = dn.Split(Char.Parse(","))
        For Each d As String In dnParts
            If d.StartsWith("DC") Then Return d.ToUpper().Replace("DC=", Nothing)
        Next
        Return Nothing
    
    End Function
    
    Private Function GetDistinguishedName(ByVal accountName As String) As String
    
        Dim nameTranslate = New ActiveDs.NameTranslate()
        nameTranslate.Set(ActiveDs.ADS_NAME_TYPE_ENUM.ADS_NAME_TYPE_NT4, accountName)
    
        Return nameTranslate.Get(ActiveDs.ADS_NAME_TYPE_ENUM.ADS_NAME_TYPE_1779)
    
    End Function
    

    There is probably better ways of doing this but it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm enumerating all databases of an SQL Server 2005 instance using SMO like as
In a Visual Studio Add-In, I'm enumerating over the members of a class in
When enumerating windows using EnumWindows, I get hundreds of handles instead of one per
I'm using an enumeration in my domain model, but I get the following error
How might I go about searching/enumerating through an NSString using a regular expression? A
If you use NSEnumerationConcurrent while enumerating a collection using blocks, does Cocoa guarantee that
Recalling this post enumerating several problems of using singletons and having seen several examples
So, I have a class with an array inside. Currently, my strategy for enumerating
I've created my own custom pseudo enumerations within my domain model to allow me
I'm enumerating Windows fonts like this: LOGFONTW lf = {0}; lf.lfCharSet = DEFAULT_CHARSET; lf.lfFaceName[0]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.