2

In Powershell, after running the Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/xyz -UseWebLogin and Get-PnPUser -WithRightsAssigned commands, I can get the list of all users that have any kind of access to a specific SharePoint Online site.

But using PnP powershell, how do I find out what kind of access they have? i.e. : Read, Contribute, etc?

1 Answer 1

3

Please try below script, this will give list of users who have direct access to the site:

# Import the PnP PowerShell module
Import-Module PnP.PowerShell

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://<site-collection-url>" -UseWebLogin

# Get the web object with role assignments included
$web = Get-PnPWeb -Includes RoleAssignments

# Get users with rights assigned
$users = Get-PnPUser -WithRightsAssigned

foreach ($user in $users) {
    # Get role assignments for the user
    $roleAssignments = $web.RoleAssignments | Where-Object { $_.Member.LoginName -eq $user.LoginName }
    foreach ($roleAssignment in $roleAssignments) {
        $roleDefinitionBindings = $roleAssignment.RoleDefinitionBindings
        foreach ($roleDefinition in $roleDefinitionBindings) {
            Write-Output "$($user.LoginName) has the following role: $($roleDefinition.Name)"
        }
    }
}

Output:

enter image description here


Here, I have one nice reference for the full site permission report: https://www.sharepointdiary.com/2018/09/sharepoint-online-site-collection-permission-report-using-powershell.html

3
  • Hi Dikesh, when I ran this script, it did not output the permissions for all users on the site. only for some users it did so
    – Lorren112
    Commented Nov 29 at 2:39
  • This script will give permissions for the users who are directly added to the site. You need total permissions report for the site then checkout this reference: sharepointdiary.com/2018/09/… Commented Nov 29 at 5:47
  • @Lorren112 please accept this answer if it is helpful to you so it will help others in the future. :) Commented Dec 2 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.