Solved

Adding to AD group with ASP and AccountManagement namespace

Posted on 2011-02-25
4
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

734 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