Solved

Adding to AD group with ASP and AccountManagement namespace

Posted on 2011-02-25
4
297 Views
Last Modified: 2012-08-14
Greetings,
I wan to use the following code as a template to add user to a particular group in AD. The problem I'm encountering is how to add to an OU group that has the same name as others. For example, Users in Miami in Florida in US versus Users in Madrid in Spain. Thanks.
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx,
                                                   IdentityType.Name,
                                                   "Domain Admins");
if (grp != null)
{
    grp.Members.Remove(ctx, IdentityType.Name, "John Smith");          
    grp.Members.Add(ctx, IdentityType.Name, "Jim Daly");
    grp.Save();
    grp.Dispose();
}
ctx.Dispose();



0
Comment
Question by:centem
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 34982746
There's a difference between an OU and a group.

An OU is a container in Active Directory, and contains things like Users, Computer Accounts and Groups.  OUs are primarily an organizational tool.  You cannot assign file access rights or operating system privileges to an OU.  An example of an OU would be the "Domain Controllers" OU, which would normally contain the computer accounts for all of the domain's controllers.  An object, like a user, can only exist in one OU at any one time.  OUs are generally referred to by their paths, which necessarily distinguishes between any two.  In your example, the two OUs might have LDAP paths such as "OU=Users,OU=Miami,OU=Florida,OU=USA,DC=somdomain,DC=com" and "OU=Users,OU=Madrid,OU=Spain,OU=Europe,DC=someDomain,DC=com" Notice that the paths work kinda like filenames - they read left-to-right most-specific to least-specific, i.e. since Miami is more specific than Florida, it's to the left.  If you imagine the tree in Active Directory Users & Computers, the top of that tree would be the right-most component of the OU's path, and one particular OU would be the left-most.  OUs generally are referred to by their LDAP path.

A group, or more accurately a "Security Group", behaves more like a special kind of user account that contains a list of other users and groups.  Groups can only contain users and other groups.  A user can be a member of any number of groups, or none.  Security privileges, like file access and privileges can be assigned to groups.  In any given domain there can not be more than one group of any given name, they each must be unique (even if they're in separate OUs).  Examples of groups would be "Domain Admins" and "Domain Users"  Security groups generally are referred to by their "user" name syntax, such as "MYDOMAIN\Domain Admins" or "MYDOMAIN\Domain Users" - but they can also be referred to by their LDAP paths (usually only when writing code though, or some similar type of activity).  So if your Miami/Users OU had a "Miami Admins" group, it's LDAP path might be "CN=Miami Admins,OU=Users,OU=Miami,OU=Florida,OU=USA,DC=somdomain,DC=com"

Are you talking about groups or OUs?

(CN = Common Name, OU = Organizational Unit, DC= Domain Context)
0
 

Author Comment

by:centem
ID: 34982941
That was extremely helpful. Thank you. I'm going to experiment a bit and let you know. Thanks
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34983241
Glad it made sense to you,  reads like gobbeldygook to me.
0
 

Author Closing Comment

by:centem
ID: 34989265
Not just helpful but also educational. Value added info.
0

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Jquery autocomplete 10 30
Achieve json result 2 34
COnsume rest client 6 12
active directory 3 26
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
[b]Ok so now I will show you how to add a user name to the description at login. [/b] First connect to your DC (Domain Controller / Active Directory Server) SET PERMISSIONS FOR SCRIPT TO UPDATE COMPUTER DESCRIPTION TO USERNAME 1. Open Active …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

760 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

21 Experts available now in Live!

Get 1:1 Help Now