{"id":317,"date":"2013-11-14T01:20:41","date_gmt":"2013-11-13T19:20:41","guid":{"rendered":"http:\/\/markwheeler.com\/wordpress\/?p=317"},"modified":"2013-11-14T01:20:41","modified_gmt":"2013-11-13T19:20:41","slug":"sql-queries-for-sharepoint-2010-site-and-user-permissions","status":"publish","type":"post","link":"https:\/\/markwheeler.com\/?p=317","title":{"rendered":"SQL queries for Sharepoint 2010 Site and User Permissions"},"content":{"rendered":"<p>In some cases you may want to audit who has what permissions to various parts of your SharePoint site or farm.<\/p>\n<p>This query will give you a list of all of your groups, the roles \/ permissions of the groups, the users in those groups, and what they have permissions to:<\/p>\n<pre>select ra.PrincipalId as 'GroupID'\n, g.Title 'GroupTitle'\n, p.ScopeUrl\n, r.Title 'RoleTitle'\n, ui.tp_Title 'UserOrADgroup' \/* Comment out to exclude individual users *\/\nfrom RoleAssignment ra with (nolock)\n\u00a0\u00a0\u00a0\u00a0 left outer join Roles r\u00a0 with (nolock) on ra.RoleId = r.RoleId\n\u00a0\u00a0\u00a0 \u00a0left outer join Perms p\u00a0 with (nolock) on ra.ScopeId = p.ScopeId\n\u00a0\u00a0\u00a0 \u00a0left outer join GroupMembership gm\u00a0 with (nolock) on ra.PrincipalId = gm.GroupId \/* Comment out to exclude individual users *\/\n   left outer join Groups g\u00a0 with (nolock) on gm.GroupId = g.ID\n--\u00a0 \u00a0left outer join Groups g\u00a0 with (nolock) on ra.PrincipalId = g.ID \/* Use if only querying for groups *\/\n\u00a0\u00a0\u00a0 \u00a0left outer join UserInfo ui\u00a0 with (nolock) on gm.MemberId = ui.tp_ID \/* Comment out to exclude individual users *\/\nwhere \u00a0p.ScopeUrl like '%' AND tp_Title not like 'NULL' AND tp_Title not like 'System Account' AND p.ScopeUrl not like '_c%'\ngroup by g.Title, P.ScopeUrl, ra.PrincipalId, r.Title order by p.ScopeUrl, g.Title<\/pre>\n<p>To get all Groups and their membership:<\/p>\n<pre>SELECT dbo.Groups.ID\n, dbo.Groups.Title\n, dbo.UserInfo.tp_Title\n, dbo.UserInfo.tp_Login \nFROM dbo.GroupMembership \nINNER JOIN dbo.Groups ON dbo.GroupMembership.SiteId = dbo.Groups.SiteId \nINNER JOIN dbo.UserInfo ON dbo.GroupMembership.MemberId = dbo.UserInfo.tp_ID \nOrder by Title<\/pre>\n<p>Other user Sharepoint Content Database Links: <a href=\"http:\/\/www.demantprasad.com\/search\/label\/Useful%20SQL%20Queries%20for%20SharePoint%20Content%20Database\" target=\"_new\" rel=\"noopener\">http:\/\/www.demantprasad.com\/search\/label\/Useful%20SQL%20Queries%20for%20SharePoint%20Content%20Database<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In some cases you may want to audit who has what permissions to various parts of your SharePoint site or farm. This query will give you a list of all of your groups, the roles \/ permissions of the groups, the users in those groups, and what they have permissions [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"footnotes":""},"categories":[2,10,11],"tags":[99,106],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-computer","category-sharepoint","category-software","tag-sharepoint-2010","tag-sql-reporting-services"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=317"}],"version-history":[{"count":0,"href":"https:\/\/markwheeler.com\/index.php?rest_route=\/wp\/v2\/posts\/317\/revisions"}],"wp:attachment":[{"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/markwheeler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}