RSS Feed
LinkedIn
Delicious
Skip to main content

Cornelius J. van Dyk's SharePoint Brain Dump

Rate this blog:
Go Search
Home
Step-by-Step Guides
Downloads
Post Archive
Capacity Planning
Architecture & Topology
Support Forums
SharePoint Team Blog
  

 Important Posts

  Complete MOSS Licensing Info
  SharePoint Speak Terminology Dictionary
  SPCAP - SharePoint Capacity Planning Tool
  Step-by-Step – A REAL world upgrade of a SharePoint Portal Server 2003 (SPS) farm to Microsoft Office SharePoint Server 2007 (MOSS)
  Best Practice - Determine if a SPUser has Admin rights to the SPWeb
  SharePoint 2010 - Good, Better, Best
Cornelius J. van Dyk's SharePoint Brain Dump > Posts > How do I? – Get a list of all users for each SharePoint site
How do I? – Get a list of all users for each SharePoint site

If you're doing an upgrade of an existing SharePoint Portal Server 2003 farm to Microsoft Office SharePoint Server 2007 you will undoubtedly run into the need to identify all site administrators in your SPS 2003 environment. If for no other reason than to notify them that their Themes will be lost during the migration to MOSS 2007, you'll be in contact with these administrators.

The question is… how do you identify all the site administrators? If you only have a hand full of sites, it can certainly be done manually, but if you dealing with a huge farm and thousands of sites, this is not practical. That is exactly where TSQL comes to the rescue.

Now as you know, we are not allowed to directly update any of the SharePoint databases as this action would invalidate your support agreement with Microsoft and put your portal in an unsupported state. That doesn't mean we can't read from it. This little SQL query will deliver the results you are looking for:

USE SharePoint_SITE
SELECT w.fullurl, w.title, u.tp_title, u.tp_login
FROM webs w, userinfo u, webgroups g
INNER JOIN webgroupmembership p
ON g.webid = p.webid
AND g.id = p.groupid
WHERE g.type = 5
AND u.tp_id = p.memberid
AND u.tp_siteid = g.siteid
AND w.id = g.webid
AND w.siteid = g.siteid
ORDER BY w.fullurl

The WebGroups table defines all the web sites and they groups that was created for each. Joining it to the WebGroupMembership table provides us with the users that belong to the groups and from there we just have to get more user information and web site information from the UserInfo and Webs tables.

If you wish to get a list of other standard user groups, just change the "g.type =" part of the statement as follows:

  1. Guest
  2. Reader
  3. Contributor
  4. Web Designer
  5. Administrator

Once you have the list, you can dump it to a .CSV file and manipulate it from Excel.

You could also download my SQL script here.

Later
C

Kick It

Comments

nspsharing.blogspot.com

thanks alot your SQL script, without any knowledge able to query the Sharepint DB.
i will learn from here ..thanks again. good job
at 11/21/2007 7:30 PM

http://www.cjvandyk.com/blog

Glad I could help!

Later
C
Cornelius J. van Dyk at 11/26/2007 10:57 AM

gary.nees@paccar.ANTISPAM.com

Do you have a similar solution for WSSV3?
at 12/7/2007 9:27 AM

mysharepoint@yahoo.ANTISPAM.com

Do you know why the results would not include some users? We have an environment with external users, but not all of them show up. I've modified your script explicitly look for tp_Login = domain\userid with no luck. I'm wondering if it has anything to do with the fact that he resides in a third level subsite? Could these profiles be kept in another table? Any ideas you have would be greatly appreciated.

Thank you so much.
at 12/19/2007 5:21 AM

Karmel

Hey Corne, how's it going?
I assume that this query is for 2003, do you have a query for 2007?
Cheers!
at 12/19/2007 10:39 AM

http://www.cjvandyk.com/blog

I've poked around the WSS 3.0 database a little bit, but have not been able to resolve this query completely due to the schema changes involved.
When I do, I'll post it to this blog...

Later
C
Cornelius J. van Dyk at 1/7/2008 7:14 AM

http://www.cjvandyk.com/blog

MySharePoint,

The reason someone might not show up in the list is if they've never actually visited the site.
This query is based on the same information as the "Site Users" web part so once the visit the site, they'll show up in the query.

Thanks
C
Cornelius J. van Dyk at 1/7/2008 7:23 AM

http://www.cjvandyk.com/blog

Hey Karmel,

Long time no see.
Yep, this is a 2003 query.
Still working on 2007.

Thanks
C
Cornelius J. van Dyk at 1/7/2008 7:25 AM

obajaber@gmail.ANTISPAM.com

Hello there,
So, you managed to figure the query for 2007? Am thinking of accessing the database directly to get the users coz it seems that it's quite tedious to use the SDK and loop through each site and it's group etc.

Or is there another way to simply get ALL users regardless of their group/role membership?
at 1/9/2008 1:30 AM

http://www.cjvandyk.com/blog

Alas, I've not had time to track through the database to find the proper query.  When I do, I'll be sure to blog it here...

Later
C
Cornelius J. van Dyk at 1/13/2008 7:15 AM

paul@nospam.com

very similar to what I'd just written.  Here's my version that goes through all sites and users/domain groups and lists each Site Group the belong to:

select

'http://<your portal url here>' + w.FullURL as [URL],
w.Title,
ui.tp_login,
wg.Title

FROM

SERVER.SITE.dbo.UserInfo ui

inner join
SERVER.SITE.dbo.WebGroups wg
on
wg.SiteId = ui.tp_SiteId

inner join
SERVER.SITE.dbo.WebGroupmembership wgm
on
wgm.WebId = wg.WebId
and
wgm.GroupID = wg.[ID]
and
ui.tp_ID = wgm.memberID

inner join
SERVER.SITE.dbo.Sites s
on
s.[Id] = ui.tp_SiteID

inner join
SERVER.SITE.dbo.Webs w
on
w.SiteId = ui.tp_SiteID

where
--Remove the Portal Areas and Personal Sites
w.FullURL not like '%personal%'
and
w.Title not in
(
'name of area you don't want',
'Administration',
'another area you don't want to list'
)
and
w.FullUrl <> 'MySite'

order by
[URL]



Enjoy....
at 2/15/2008 7:50 AM

http://www.cjvandyk.com/blog

Hey Paul,

Thanks for sharing.

Later
C
Cornelius J. van Dyk at 2/20/2008 1:46 PM

murtuzfg@gmail.ANTISPAM.com

cab you have same one (all sites and users/domain groups and lists each Site Group the belong to) for MOSS 2007
at 3/3/2008 10:01 PM

mfarooq@gmail.ANTISPAM.com

Hi Paul,

Can you please explain your sql query for 2007. I am using MOSS 2007 and wants to get all site admin users.

Hope to hear from you soon,

Regards
at 6/3/2008 6:40 AM

anwarul.haque@metaoption.ANTISPAM.com

How to get all portals site name in MOOS 2007 by SQL Query?



Thanks in Advance
Haque A
at 10/14/2008 7:13 AM

www.loyola.edu

Will this script work against the 2007 MOSS db?
at 3/6/2009 11:54 AM

p.ravirao@gmail.ANTISPAM.com

Thanks a lot!
   saved lot of time to me.
at 7/6/2009 11:47 PM

http://www.cjvandyk.com/blog

Hey p.ravirao,

Glad it was useful to you!

Later
C
Cornelius J. van Dyk at 7/10/2009 1:58 AM

http://donthaveblog.com

Thanks a lot. It worked.
at 7/9/2010 10:56 AM

Add Comment

PLEASE NOTE
Comments are moderated so posting your comment here, will NOT make it visible right away.  Once I've reviewed your comment, I will publish it for all to see.  This is unfortunately needed in order to deal with all the crapware and spambots that post to my blog on a regular basis.

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Email or Blog URL *


Body *


Attachments