If you need to return email addresses for the users, just add one more output: $SPRole.Member.Email
.
Here is the modified script:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$SPSiteUrl = "<siteURL>"
$SPSite = New-Object Microsoft.SharePoint.SPSite($SPSiteUrl);
$ExportFile = "C:\Temp\PermissionReport.csv"
"Web Title `t Web URL`t List Title `t User or Group `t User Email `t Role `t Inherited" | out-file $ExportFile
foreach ($WebPath in $SPSite.AllWebs) {
if ($WebPath.HasUniqueRoleAssignments) {
$SPRoles = $WebPath.RoleAssignments;
foreach ($SPRole in $SPRoles) {
foreach ($SPRoleDefinition in $SPRole.RoleDefinitionBindings) {
"$($WebPath.Title)`t $($WebPath.Url)`t `t $($SPRole.Member.Name)`t $($SPRole.Member.Email)`t $($SPRoleDefinition.Name)`t $($WebPath.HasUniqueRoleAssignments)" | out-file $ExportFile -append
}
}
}
foreach ($List in $WebPath.Lists) {
if ($List.HasUniqueRoleAssignments) {
$SPRoles = $List.RoleAssignments;
foreach ($SPRole in $SPRoles) {
foreach ($SPRoleDefinition in $SPRole.RoleDefinitionBindings) {
"$($WebPath.Title)`t $($WebPath.Url)`t $($List.Title)`t $($SPRole.Member.Name)`t `t $($SPRoleDefinition.Name)`t $($List.HasUniqueRoleAssignments)" | out-file $ExportFile -append
}
}
}
}
}
$SPSite.Dispose();
And to list all users inside the groups, you can refer to the references here for sample scripts:
SharePoint Users and Groups Permission Analysis Report for Site Collection.
SharePoint: User Permissions detail report for a Web Application.
I will put one of the sample scripts as an attachment since it is too long to display in this thread: 38976-samplesharepoint-server-user-permissions-detail-re.txt
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
If an Answer is helpful, please click "Accept Answer" and upvote it.
**Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread. **