Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Adding to AD group with ASP and AccountManagement namespace

Posted on 2011-02-25
4
Medium Priority
?
318 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 2000 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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

660 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