Answered by:
Group Permission list with site URL's

Question
-
I need a report that will show the Group name and the URLs that the group is part of. As you can see it's possible to grab the information in the GUI of SharePoint Online using view site collection permissions - webpage dialog box but it's only one group at a time. Is there any out of box solutions. Or third party solutions? Thanks
Thursday, August 24, 2017 6:11 PM
Answers
-
Hi,
Modify the code as below to achieve it.
<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { function exportTableToCSV($table, filename) { var $headers = $table.find('tr:has(th)') ,$rows = $table.find('tr:has(td)') // Temporary delimiter characters unlikely to be typed by keyboard // This is to avoid accidentally splitting the actual contents ,tmpColDelim = String.fromCharCode(11) // vertical tab character ,tmpRowDelim = String.fromCharCode(0) // null character // actual delimiter characters for CSV format ,colDelim = '","' ,rowDelim = '"\r\n"'; // Grab text from table into CSV formatted string var csv = '"'; csv += formatRows($headers.map(grabRow)); csv += rowDelim; csv += formatRows($rows.map(grabRow)) + '"'; // Data URI var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv); // For IE (tested 10+) if (window.navigator.msSaveOrOpenBlob) { var blob = new Blob([decodeURIComponent(encodeURI(csv))], { type: "text/csv;charset=utf-8;" }); navigator.msSaveBlob(blob, filename); } else { $(this) .attr({ 'download': filename ,'href': csvData //,'target' : '_blank' //if you want it to open in a new window }); } //------------------------------------------------------------ // Helper Functions //------------------------------------------------------------ // Format the output so it has the appropriate delimiters function formatRows(rows){ return rows.get().join(tmpRowDelim) .split(tmpRowDelim).join(rowDelim) .split(tmpColDelim).join(colDelim); } // Grab and format a row from the table function grabRow(i,row){ var $row = $(row); //for some reason $cols = $row.find('td') || $row.find('th') won't work... var $cols = $row.find('td'); if(!$cols.length) $cols = $row.find('th'); return $cols.map(grabCol) .get().join(tmpColDelim); } // Grab and format a column from the table function grabCol(j,col){ var $col = $(col), $text = $col.text(); return $text.replace('"', '""'); // escape double quotes } } $("#GetGroupPermissions").click(function(){ // begin work to call across network var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups?$select=Id,Title"; // execute AJAX request $.ajax({ url: requestUri, type: "GET", async: false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { var groups=data.d.results; var tableHtml="<table><tbody><tr><th>Group Name</th><th>URL</th><th>Permission</th></tr>"; for(var i=0;i<groups.length;i++){ var group=groups[i]; var permissionsTable=getGroupPermissions(group.Id); $(permissionsTable).find("tr").each(function(i){ if(i>0){ tableHtml+="<tr><td>"+group.Title+"</td>"+$(this).html()+"</tr>"; } }); } tableHtml+="</tbody></table>"; exportTableToCSV.apply($("#GetGroupPermissions"), [$(tableHtml), "GroupPermissions.csv"]); //exportTableToCSV($("#GetGroupPermissions"),$(tableHtml), "GroupPermissions.csv"); }, error: function () { //alert("Failed to get details"); } }); }); }); function getGroupPermissions(groupId){ var results; // begin work to call across network var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/ViewGroupPermissions.aspx?ID="+groupId; // execute AJAX request $.ajax({ url: requestUri, type: "GET", async: false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { results=$(data).find(".ms-listviewtable").prop("outerHTML"); }, error: function () { results=""; } }); return results; } </script> <a id="GetGroupPermissions" href="#">Export Permissions To Csv</a>
Best Regards,
Dennis
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- Proposed as answer by Arleta WanatMVP Monday, August 28, 2017 12:46 PM
- Marked as answer by Stephen Suda Tuesday, August 29, 2017 2:46 PM
Monday, August 28, 2017 7:24 AM
All replies
-
Hi,
Create a web part page and add the following code into a content editor web part in this page.
<script src="//code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { // begin work to call across network var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups?$select=Id,Title"; // execute AJAX request $.ajax({ url: requestUri, type: "GET", headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { var groups=data.d.results; for(var i=0;i<groups.length;i++){ var group=groups[i]; var html="<p><h2>"+group.Title+"</h2><br/>"+getGroupPermissions(group.Id)+"</p>"; $("#getAllGroupPermissions").append(html); } }, error: function () { alert("Failed to get details"); } }); }); function getGroupPermissions(groupId){ var results; // begin work to call across network var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/ViewGroupPermissions.aspx?ID="+groupId; // execute AJAX request $.ajax({ url: requestUri, type: "GET", async: false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { results=$(data).find(".ms-listviewtable").prop("outerHTML"); }, error: function () { results=""; } }); return results; } </script> <div id="getAllGroupPermissions"> </div>
Best Regards,
Dennis
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- Edited by Dennis Guo Friday, August 25, 2017 8:58 AM
Friday, August 25, 2017 8:57 AM -
Thanks, is there a way to get this information into a csv txt file on a report and display the columns like this:
Group Name URL Permission
Thanks, Stephen
Friday, August 25, 2017 1:33 PM -
Hi,
Modify the code as below to achieve it.
<script src="//code.jquery.com/jquery-1.11.0.min.js" type="text/javascript"></script> <script type="text/javascript"> $(function () { function exportTableToCSV($table, filename) { var $headers = $table.find('tr:has(th)') ,$rows = $table.find('tr:has(td)') // Temporary delimiter characters unlikely to be typed by keyboard // This is to avoid accidentally splitting the actual contents ,tmpColDelim = String.fromCharCode(11) // vertical tab character ,tmpRowDelim = String.fromCharCode(0) // null character // actual delimiter characters for CSV format ,colDelim = '","' ,rowDelim = '"\r\n"'; // Grab text from table into CSV formatted string var csv = '"'; csv += formatRows($headers.map(grabRow)); csv += rowDelim; csv += formatRows($rows.map(grabRow)) + '"'; // Data URI var csvData = 'data:application/csv;charset=utf-8,' + encodeURIComponent(csv); // For IE (tested 10+) if (window.navigator.msSaveOrOpenBlob) { var blob = new Blob([decodeURIComponent(encodeURI(csv))], { type: "text/csv;charset=utf-8;" }); navigator.msSaveBlob(blob, filename); } else { $(this) .attr({ 'download': filename ,'href': csvData //,'target' : '_blank' //if you want it to open in a new window }); } //------------------------------------------------------------ // Helper Functions //------------------------------------------------------------ // Format the output so it has the appropriate delimiters function formatRows(rows){ return rows.get().join(tmpRowDelim) .split(tmpRowDelim).join(rowDelim) .split(tmpColDelim).join(colDelim); } // Grab and format a row from the table function grabRow(i,row){ var $row = $(row); //for some reason $cols = $row.find('td') || $row.find('th') won't work... var $cols = $row.find('td'); if(!$cols.length) $cols = $row.find('th'); return $cols.map(grabCol) .get().join(tmpColDelim); } // Grab and format a column from the table function grabCol(j,col){ var $col = $(col), $text = $col.text(); return $text.replace('"', '""'); // escape double quotes } } $("#GetGroupPermissions").click(function(){ // begin work to call across network var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups?$select=Id,Title"; // execute AJAX request $.ajax({ url: requestUri, type: "GET", async: false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { var groups=data.d.results; var tableHtml="<table><tbody><tr><th>Group Name</th><th>URL</th><th>Permission</th></tr>"; for(var i=0;i<groups.length;i++){ var group=groups[i]; var permissionsTable=getGroupPermissions(group.Id); $(permissionsTable).find("tr").each(function(i){ if(i>0){ tableHtml+="<tr><td>"+group.Title+"</td>"+$(this).html()+"</tr>"; } }); } tableHtml+="</tbody></table>"; exportTableToCSV.apply($("#GetGroupPermissions"), [$(tableHtml), "GroupPermissions.csv"]); //exportTableToCSV($("#GetGroupPermissions"),$(tableHtml), "GroupPermissions.csv"); }, error: function () { //alert("Failed to get details"); } }); }); }); function getGroupPermissions(groupId){ var results; // begin work to call across network var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/ViewGroupPermissions.aspx?ID="+groupId; // execute AJAX request $.ajax({ url: requestUri, type: "GET", async: false, headers: { "ACCEPT": "application/json;odata=verbose" }, success: function (data) { results=$(data).find(".ms-listviewtable").prop("outerHTML"); }, error: function () { results=""; } }); return results; } </script> <a id="GetGroupPermissions" href="#">Export Permissions To Csv</a>
Best Regards,
Dennis
Please remember to mark the replies as answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- Proposed as answer by Arleta WanatMVP Monday, August 28, 2017 12:46 PM
- Marked as answer by Stephen Suda Tuesday, August 29, 2017 2:46 PM
Monday, August 28, 2017 7:24 AM -
Thanks this works for one of my site collection, but for some reason site collections with more then 100 groups, the script freezes up. Meaning it does nothing. ThanksTuesday, August 29, 2017 2:46 PM