Solved

Add User to AD Group from another Domain

Posted on 2010-09-01
8
270 Views
Last Modified: 2012-05-10
How do you add a user to an AD group in one domain (external), from another domain (internal), in asp.net? I know they're referenced in the external domain by their SID, but I'm not sure how to add a user that way.  Here is the code I have for adding a new user: (Note: code taken from http://www.vbdotnetheaven.com/UploadFile/ecabral/ADandNETInVB11112005020216AM/ADandNETInVB.aspx)

    Dim dirEntry As DirectoryEntry
    If internal Then
        dirEntry = GetDirectoryEntry(True, False)
    Else
        dirEntry = GetDirectoryEntry(False, False)
    End If

    Dim deSearch As DirectorySearcher = New DirectorySearcher()
    'deSearch.SearchRoot = de
    deSearch.Filter = "(&(objectClass=group) (cn=" & GroupName & "))"
    Dim results As SearchResultCollection = deSearch.FindAll()
    Dim isGroupMember As Boolean = False
    If results.Count > 0 Then
        Dim group As New DirectoryEntry(results(0).Path)
        Dim members As Object = group.Invoke("Members", Nothing)
        For Each member As Object In CType(members, IEnumerable)
            Dim x As DirectoryEntry = New DirectoryEntry(member)
            Dim name As String = x.Name
            If name <> deUser.Name Then
                isGroupMember = False
            Else
                isGroupMember = True
                Exit For
            End If
        Next member
        If (Not isGroupMember) Then
            group.Invoke("Add", New Object() {deUser.Path.ToString()})
        End If
        group.Close()
    End If

Open in new window


0
Comment
Question by:Rainverse
  • 3
  • 2
8 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 33587200
check out the code at this link and see if it is what you are looking for:
                http://www.codeproject.com/KB/vb/ActiveDirectory_Group_VB.aspx
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 33763803
I object to deleting this question because I believe the cited reference source (which has been viewed 41,000+ times) directly answers the question, and should remain as part of the  EE Knowledge Base.
0
 
LVL 5

Accepted Solution

by:
Rainverse earned 0 total points
ID: 33764105
Actually it didn't. That reference is very helpful for most required AD actions but not for what I needed to do. The answer turned out to be the following:

You have to get a string value of the SID of the user in the internal domain. Then you can add that to the external AD group and it acts as a reference pointer to the internal AD user record.
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 33764270
Rainverse,
Thank you for posting the solution to your question.  That gives us even more reason not to delete this post.  It should be saved in the knowledge base for the benefit of EE users who have a similar problem in the future.
0
 
LVL 5

Author Comment

by:Rainverse
ID: 33764393
I usually do. Just been super busy.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now