Efficiently List User Permissions in SharePoint with PowerShell

In this post, we will provide a PowerShell script that helps you list user permissions for a SharePoint site. Understanding who has access to what information is crucial for managing security and compliance levels in your organization. This script will retrieve and display a detailed list of users and their corresponding permissions on the specified SharePoint site, making it easier for administrators to ensure that access levels are appropriate.
Here is the PowerShell script for listing SharePoint user permissions:

# Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/YourSite"
$credential = Get-Credential
Connect-PnPOnline -Url $siteUrl -Credentials $credential
# Get all users and their permissions for the site
$users = Get-PnPUser
# Create a report of user permissions
$permissionReport = foreach ($user in $users) {
    $permissions = Get-PnPUserEffectivePermissions -User $user.LoginName
    [PSCustomObject]@{
        User          = $user.LoginName
        Permissions   = ($permissions | ForEach-Object { $_.Name }) -join ', '
    }
}
# Output the permission report
$permissionReport | Format-Table -AutoSize
Write-Host "User permissions listed successfully for the site."