How to get a list of users in SharePoint 2007 groups with a SQL query on the content database

If you are anything like me I hate clicking around 100’s of SharePoint groups to find out what users are in what groups.  This Query can be run against the content database of a MOSS 2007 farm to get the members of a given, or multiple groups. 

SELECT distinct
Webs.Title as 'Web'
,[Groups].[Title] as 'group'  ,
[UserInfo].tp_Title as 'user' ,
[tp_Email]
FROM  Webs
join [Groups] on Webs.SiteId = Groups.SiteID
join [GroupMembership] on [GroupMembership].GroupId = [Groups].ID and [GroupMembership].SiteID = [Groups].SiteID
join [UserInfo] on [UserInfo].tp_ID = [GroupMembership].MemberId and [UserInfo].tp_SiteID = [GroupMembership].SiteID
where
[Webs].ParentWebId is null and
tp_IsActive = 1 and
tp_Email is not null and
Webs.Title in (@Region) AND
  (
 Groups.Title like '%Members%'
 or Groups.Title like '%Visitors%'
 )
 order by Web, [Groups].[Title]

Comments

Popular posts from this blog

Metastorm - Open form in an action from a list or link

Corporate Intranet Information Architecture – a Publishing Site

No Search Results in SharePoint Contextual Search OSSSearchResults.aspx