I've come across the occasion, once or twice, where the customer wanted to be able to display all the users of a particular Active Directory group in a SharePoint list. Though a seemingly simple request, it quickly turned into a headache for me. Couldn't I use Audiences or a similar resource to populate a list? I finally came up with this solution. Although it's something of a kludge, it works reliably once it's set up.
It is possible to query Active Directory directly, as if it was a database server. Setting this up is somewhat complex, but most steps only need to be performed once.
Resources you'll need:
- An account with Read Access to Active Directory
- This account will be reading AD on behalf of the query
- SQL server 2005
- You will be working in SSMS
- You will need to have permission to create a linked server, create a database, and create objects in the database.
- SharePoint Designer 2007
- SPD is required to be able to create data views on SharePoint pages. No other tool can do this.
- Authoring access to the SharePoint page(s)
- Part One: Using SQL Server Management Studio, perform the following steps:
- First, we need to set up linked server access to AD:
--Add a linked server which will connect to Active Directory Services (ADSI)
--This only needs to be done once.
sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces',
'ADSDSOObject', 'adsdatasource'
GO
Note: you may need to modify this Linked Server as follows:
First, go to the Linked Server Properties:

Next, specify that the connection will be made using a specific context. In this case we used the Domain Administrator, but really any account with Read Access to the AD schema would be fine.

- Part Two: Create Database, View, and SQL Login
- Create a database
- To host the views we'll be running against Active Directory, we'll need to set up a database. You can use an existing one if you want, but I prefer to keep these items separate from my other production data.
- I use the name ADLookup.
- The database doesn't need to be anything fancy. Just accept defaults and continue.

- Create a SQL Login
- In this example I created an account named "ADLookup", with the following options:
- Authentication type: SQL Server
- Note: this solution depends on the SQL security being set to Mixed Mode. If you are at a site that requires Windows Only authentication I don't think this will work for you. There is probably an alternative method, but I haven't looked into it yet.
- Default Database: ADLookup
- Server Roles: None
- User Mapping:
-- Now show the login name and display name for all users in the specified group.
USE [adlookup] --This is the user database to hold all of the views we'll be creating
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*Show the login name and display name for all users in the specified group.*/
CREATE VIEW [dbo].[vw_groupname]
AS
SELECT sAMAccountName AS [Login Name], givenName AS [First Name], sn AS [Last Name], displayName AS [Full Name], mail AS [E-Mail Address],
telephoneNumber AS Phone
FROM OPENQUERY(ADSI,
'SELECT sAMAccountName, givenName, sn,displayName, mail, telephoneNumber
FROM
''LDAP://dc=YourDomain,dc=local''
WHERE objectClass = ''user'' and objectCategory=''person''
AND memberOf = ''CN=YourGroup,OU=YourOU, dc=YourDomain,dc=local''')
AS derivedtbl_1
-
Notes:
- This will return all members of the "YourGroup" group, located at "YourDomain.local/YourOU/YourGroup"
- The "objectCategory" parameter is to differentiate between users and computers (which can also be members of a group).
- This query can then be copied into a view, which will dynamically return all users in a given group.
- Then SharePoint can use this view to populate a Data View. This workaround allows us to show all the users who are members of the group and display it on the page, something SharePoint can't seem to do by itself.
-
Customization:
- Specify the view name
- Use the naming convention: vw_GroupName (e.g. vw_YourGroup)
- In this example I use a view named vw_AnchorageStaff.
- This should match the name of the AD group, to avoid confusion
- Specify the properties to be queried per user in the group.
- The above query returns the following properties:
sAMAccountName AS [Login Name],
givenName AS [First Name],
sn AS [Last Name],
displayName AS [Full Name],
mail AS [E-Mail Address],
telephoneNumber AS Phone
-
Run the view:
- It should return the right number of records and columns.

- Part Three: Using SharePoint Designer, create a Data View
- In SPD, go to File-->Open Site and browse to the site you wish to work with.
- You may wish to update an existing page or create a new page.
- Click in an available area on the SharePoint page.
- On the page to be edited, click Insert-->Data View

- A DataView control is added.

- In the Data Source Library tab of the task pane, click Connect to a Database.

- In the Data Source Connection dialog, click Configure Database Connection.

- In the Configure Database Connection dialog, enter connection information for your SQL server. In this case I am connecting to an instance named "Sharepoint".

- Note: the ADLOOKUP user is a SQL user and needs to have (at least) read access to all views in the ADLOOKUP database.
- Click OK to acknowledge that passwords are passed in clear text.

- In the Data Source Properties dialog, click the Fields button to select which fields to include in this view.

- Move fields over to add or remove them from the view.

- In the Data Source Library pane, click the drop down arrow next to the view we just added and select "Show Data".

- The Data Source Details tab is activated and you see the fields available to be put on the page.
