Wayne Hall

All MindsharpBlogs

Wayne's World Famous Sharepoint Blog

My Links

Post Categories

Archives

Image Galleries

Blog Stats

Bloggers

Importing only a specific group into sharepoint profile database (via LDAP)

Quick Answer

This will help you if you already know LDAP and how to configure sharepoint's profile import settings.

Create a custom connection source in profile import and specify the following in the User Filter field:

(&(objectCategory=Person)(objectClass=User)(memberOf=[distinguised name of the group]))

Overview

If your org is like ours,  you might have a *ton* of accounts in Active Directory, and less than half of them are active employees that need to have a profile in sharepoint.  Sometimes you might have a lot of service accounts, disabled accounts, test accounts, or you might like keeping accounts of old employees around because of legal or ease-of-restore needs.  Or maybe you're just too busy to delete old accounts.  Or, um, maybe you're lazy? :)

Either way, when you set up Sharepoint the first time and you do the import, you might realize... “whoa! we gotta lotta accounts!”  Then you realize that not only are you taking up space in sharepoint (really, not that much compared to everything else), but if ever you want to enumerate the list and display it somewhere, you'd have some heavy filtering to do.  Wouldn't it be cleaner if just active employees had profiles in Sharepoint?  And what about CAL's?  If you're paying by the CAL, it might be easier to justify 500 CAL purchase even though you have 1500 accounts in A/D when you limit the profile database to 500 or 600.

So I recently started looking for a way to limit this in the profile import. In our organization, all active employees are a member of a specific corporate mailing list / security group. This group in A/D is a Universal Security group that's mail-enabled, so we use it for granting reader rights on calendars, we use it as a filter for who gets imported into other corporate apps such as “Track-IT!” from Intuit, and I really wanted to use it to determine who to import into the portal profile database.  For this example. let's call it “Corporate List“.

I saw a couple of posts here and there, but nothing solid or anything that could be construed as a how-to.  Here's what I had found before tackling it with a consultant we had onsite (I hear he's soon moving to mindsharpblogs, right Todd? :) ).

http://www.sharepointwatch.com/top/ng/group~1/~1722~__Import-user-profile-from-Active-Directory-group/index.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adsi/adsi/search_filter_syntax.asp
http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm

But none of them really answered the question.

So here it is.  First the background then the solution.

Background:

  1. You configure profile imports by going to Site Settings > Manage profile database > Configure profile import.
  2. By default, Sharepoint is smart enough to know your domain and can just select users from the one current domain.  This is good for most organizations, and it's easy to do for quick out-of-the-box implementations.
  3. Behind the scenes, what sharepoint is doing is an LDAP query to the first domain controller it can find and specifies the following as a filter on the LDAP query:

         (&(objectCategory=Person)(objectClass=User))
  4. If you've not been exposed to LDAP yet, here's your chance.  There's a neat utility Microsoft makes called LDIFDE that lets you import and export content to and from Active Directory.  It can be dangerous if you use import mode (-i) without knowing what you're doing. However, it can also shed light (like ADSIEdit, another dangerous tool in the hands of the foolhardy, but an amazingly useful tool to learn the innards) and be immensely helpful in troubleshooting)
  5. You can see what sharepoint is doing by running the following command (say, on a domain controller)

    C:\> 
    ldifde -f usersindomain.txt -r “(&(objectCategory=Person)(objectClass=User))“
    Connecting to "[domain controller].[domain]"
    Logging in as current user using SSPI
    Exporting directory to file usersindomain.txt
    Searching for entries...
    Writing out entries.............................................................
    ................................................................................
    ................................................................................
    [snip] ...........
    792 entries exported
    The command has completed successfully

    This writes the results into a file called usersindomain.txt.

    You can also do some basic wildcarding -- so for example let's say I wanted just to get the records that had a CN (common name) that started with “Wayne“.  I would run:

    C:\>ldifde -f usersindomain.txt -r "(&(objectCategory=Person)(objectClass=User)(cn=Wayne*))
    Connecting to "[domain controller].[domain]"
    Logging in as current user using SSPI
    Exporting directory to file usersindomain.txt
    Searching for entries...
    Writing out entries..
    2 entries exported
    The command has completed successfully

    Never mind the fact that I just overwrote my file :)

    What you learn from this is that you can “AND“ together arguments.  In the first example, we're saying “pull the objects that are in the “Person“ category AND give me only the ones that are in the “User“ class.“.  In the second example, we're also specifying that CN needs to start with “Wayne“.
  6. If you take a look at the resulting file, you can start getting a headache, but after that passes, you get an idea of what's in the directory.  What I care about, though, is... how do I specify group membership?  I mean, this file has a HUGE amount of information in it (some of it pretty cool, actually), but I just want to limit by group.
  7. So look in the resulting file and look for the group you care about.  It will have an entry like the following:

    memberOf:
     CN=Corporate List,OU=Administrative,OU=Distribution Lists,OU=Domain,DC=domain,DC=local

    This second line starting with CN is called the “Distinguished name“ of the group.  With this label, you should be able to uniquely identify this object.  You may also notice that there's an entry for every group that the user is a member of.  What's neat about this is that Active Directory is attaching multiple properties to the object so that you don't have to search through a list of groups and find a match for yours.  You can just say “if memberof equals this distinguished name, return it in the list“.
  8. So it stands to reason that we should be able to use this as one of our “AND“ statements in the LDIFDE test.  So we add it in there to find out:

    C:\>ldifde -f output2.ldf -r "(&(objectCategory=Person)(objectClass=User)(memberOf=CN=Corporate List,OU=Administrative,OU=Distribution Lists,OU=Domain,DC=domain,DC=local))
    Connecting to "[domain controller].[domain]"
    Logging in as current user using SSPI
    Exporting directory to file output2.ldf
    Searching for entries...
    Writing out entries.............................................................
    ................................................................................
    ................................................................................
    ..................................................
    271 entries exported
    The command has completed successfully

    Cool.  Let's say that number matches how many people should be in the list, and now we have a construct for importing just the right people into the portal.
  9. [optional] If you wanted to specify additional groups, you could use the OR clause, implemented by a PIPE ( | ) symbol.  However, be warned that LDAP prepends the operator to the arguments.  So if you're used to perl or C or something that processes the operator BETWEEN arguments, you might get confused.

    Do you remember how we AND'ed arguments together by doing (&(argument1)(argument2)) ?  Well OR is the same way.  Here's an example from above page

          (&(objectClass=user) | (cn=andy*)(cn=steve*)(cn=margaret*))

    gets all user entries with a common name that starts with andy, steve or margaret.  Notice the OR comes before the arguments.  If you wanted to select people of multiple groups... say you have three groups called “Corporate East,“ “Corporate West“ and “Corporate EMEA“, AND they're all in different OU's in your domain, AND you don't have a group that houses all of those people, BUT you want to import them all....

    You can use the OR operator on the memberof property.  It would probably look something like this: 
    (I'll try to show different colors to differentiate the clauses.  note that this is not tested, just my hand-typed estimate)

    (&(objectCategory=Person)(objectClass=User) | (memberOf=CN=Corporate East,OU=Administrative,OU=Distribution Lists,OU=East,DC=domain,DC=local)(memberOf=CN=Corporate West,OU=Administrative,OU=Distribution Lists,OU=West,DC=domain,DC=local)(memberOf=CN=Corporate EMEA,OU=Administrative,OU=Distribution Lists,OU=EMEA,DC=domain,DC=local))


Answer:

  1. Go to Site Settings > Manage profile database > Configure profile import.
  2. Select “Custom Source“.  This will let you create import connections
    1. By the way, this is also how you can configure to import from multiple domains in a forest without having to specify the entire forest
    2. Also, this is how you get the “Manage connections“ link on the Manage Profile Database screen
  3. It should ask you for the connection settings
  4. Fill in User Filter -- For our purposes, we put in the parameter that we used in ldifde with the -r option (see Background above)

    Format:
    (&(objectCategory=Person)(objectClass=User)(memberOf=[distinguised name of the group]))

    Example:
    (&(objectCategory=Person)(objectClass=User)(memberOf=CN=Corporate List,OU=Administrative,OU=Distribution Lists,OU=Domain,DC=domain,DC=local))
  5. You could also modify Search base to specify an OU, but I haven't tested that. 
  6. I didn't change any other settings. My settings have
    1. Auto discover domain controller
    2. Port: 389
    3. Timeout: 120 seconds
    4. Scope: Subtree
    5. Page size: 10
    6. Page timeout: 120 seconds

Hope this helps!

 

posted on Wednesday, June 15, 2005 8:19 AM

Feedback

# re: Importing only a specific group into sharepoint profile database (via LDAP) 6/15/2005 9:58 AM Arno Nel

Dude, just got to say, its an absolute pleasure reading your posts. keep up the good work

# re: Importing only a specific group into sharepoint profile database (via LDAP) 6/16/2005 12:25 AM Amardeep Dabass

Thanx buddy ... we were looking for exactly this !!!

# re: Importing only a specific group into sharepoint profile database (via LDAP) 6/16/2005 9:34 AM Bill English

Great Post, Wayne. Nicely done.

# Import von Benutzerkonten konfigurieren 6/21/2005 2:06 PM SharePoint, SharePoint and stuff

Wayne Hall hat ein sehr guten KnowHow-Artikel geschrieben wie man beim Import von Benutzerkonten in SharePoint unerw

# re: Importing only a specific group into sharepoint profile database (via LDAP) 3/7/2006 6:55 AM Michael Leeming

Nice Article...

I have also been using this type of import filter, but I am annoyed by the fact that the account used to crawl the site is automatically added to the profile db everytime the site is crawled. This is also happens if you log in with a dummy user, not incl. in the Profile import.

The main problem about this is that these "system" accounts show up in user lookup dropdown boxes in lists. And their personal site may show up in search result also.

Have anyone found a way to disable non-imported users from being added automatically to the profile database?

Another question is it required that the crawler account is in the profile db?

Regards

Michael

# re: Importing only a specific group into sharepoint profile database (via LDAP) 6/14/2006 5:23 AM Madhur Ahuja

How can I import distribution groups instead of users.

Mail me at madhur.ahuja@wipro.com

# re: Importing only a specific group into sharepoint profile database (via LDAP) 7/18/2006 3:14 PM Mark Wagner

Excellent post Wayne! Thanks for the great article and taking the time to post it. I am using this for a client implementing SharePoint Server 2007 Beta2 - and it works great!

# re: Importing only a specific group into sharepoint profile database (via LDAP) 5/4/2007 4:38 AM Stian Svendsen

Just thought I'd share this with you, as I just figured out how to do it after searching for a solution for several months.
As most people in most organizations has a e-mail (at least in my case, so this will be the common factor), and you don't want to include disabled users you might want to use this search filter:

(&(objectCategory=Person)(objectClass=User)( !(userAccountControl:1.2.840.113556.1.4.803:=2))(mail=*))

# re: Importing only a specific group into sharepoint profile database (via LDAP) 3/17/2008 2:15 PM Katherine

Hi Wayne,
We found that the syntax you offered above:
(&(objectCategory=Person)(objectClass=User) | (memberOf=CN=Corporate East,OU=Administrative,OU=Distribution Lists,OU=East,DC=domain,DC=local)(memberOf=CN=Corporate West,OU=Administrative,OU=Distribution Lists,OU=West,DC=domain,DC=local)(memberOf=CN=Corporate EMEA,OU=Administrative,OU=Distribution Lists,OU=EMEA,DC=domain,DC=local))

requires a paren before the OR separator (pipe) and a final closing paren, like this:

(&(objectCategory=Person)(objectClass=User)(|(memberOf=CN=Corporate East,OU=Administrative,OU=Distribution Lists,OU=East,DC=domain,DC=local)(memberOf=CN=Corporate West,OU=Administrative,OU=Distribution Lists,OU=West,DC=domain,DC=local)(memberOf=CN=Corporate EMEA,OU=Administrative,OU=Distribution Lists,OU=EMEA,DC=domain,DC=local)))

# re: Importing only a specific group into sharepoint profile database (via LDAP) 8/14/2008 1:53 PM bedava oyunlar

I dont understand anything

# re: Importing only a specific group into sharepoint profile database (via LDAP) 10/30/2008 6:34 AM sohbet

need Thank you!

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/17/2008 2:49 AM mirc

thanks.

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/17/2008 2:52 AM Mırc

thanks

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/18/2008 1:48 AM çet

thanks.

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/18/2008 1:48 AM chat

thanks.

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/18/2008 1:50 AM chat

thanks.

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/18/2008 1:50 AM sohbet

thanks.

# re: Importing only a specific group into sharepoint profile database (via LDAP) 11/21/2008 2:39 AM mircalem

thanks.

Title  
Name  
Url
CAPTCHA
Protected by Clearscreen.SharpHIPEnter the code you see:
Comments