Export list of user having access to specific folder in sharepoint

Rabin Rasaili 21 Reputation points
2022-12-19T23:16:28.3+00:00

Hi All,

I am trying to export the list of users having permission on a specific SharePoint folder.
Is there any way to do this?

Thanks in advance.

Microsoft 365 and Office SharePoint Server For business
Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jinwei Li-MSFT 4,736 Reputation points Microsoft External Staff
    2022-12-20T07:03:08.307+00:00

    Hi @Rabin Rasaili ,

    Folder level permission in SharePoint Online helps to obtain fine-grained permissions, and they are an important part of SharePoint Online security. This Microsoft article explains in detail the process.
    How to Export Folder Permissions to Excel or CSV File


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    1 person found this answer helpful.

  2. AllenXu-MSFT 24,941 Reputation points Moderator
    2023-01-04T08:17:52.763+00:00

    Hi @Rabin Rasaili ,

    Here is the PowerShell to get specific folder permissions in SharePoint Online:

    #Load SharePoint CSOM Assemblies  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"  
    Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"  
        
    #Function to Get Folder Permissions  
    Function Get-SPOFolderPermission([String]$SiteURL, [String]$FolderRelativeURL)  
    {  
        Try{  
            #Setup the context  
            $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)  
            $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)  
            
            #Get the Folder  
            $Folder = $Ctx.Web.GetFolderByServerRelativeUrl($FolderRelativeURL)  
            $Ctx.Load($Folder)  
            $Ctx.ExecuteQuery()  
       
            #Get permissions assigned to the Folder  
            $RoleAssignments = $Folder.ListItemAllFields.RoleAssignments  
            $Ctx.Load($RoleAssignments)  
            $Ctx.ExecuteQuery()  
       
            #Loop through each permission assigned and extract details  
            $PermissionCollection = @()  
            Foreach($RoleAssignment in $RoleAssignments)  
            {  
                $Ctx.Load($RoleAssignment.Member)  
                $Ctx.executeQuery()  
       
                #Get the User Type  
                $PermissionType = $RoleAssignment.Member.PrincipalType  
       
                #Get the Permission Levels assigned  
                $Ctx.Load($RoleAssignment.RoleDefinitionBindings)  
                $Ctx.ExecuteQuery()  
                $PermissionLevels = ($RoleAssignment.RoleDefinitionBindings | Select -ExpandProperty Name) -join ","  
                   
                #Get the User/Group Name  
                $Name = $RoleAssignment.Member.Title # $RoleAssignment.Member.LoginName  
       
                #Add the Data to Object  
                $Permissions = New-Object PSObject  
                $Permissions | Add-Member NoteProperty Name($Name)  
                $Permissions | Add-Member NoteProperty Type($PermissionType)  
                $Permissions | Add-Member NoteProperty PermissionLevels($PermissionLevels)  
                $PermissionCollection += $Permissions  
            }  
            Return $PermissionCollection  
        }  
        Catch {  
        write-host -f Red "Error Getting Folder Permissions!" $_.Exception.Message  
        }  
    }  
        
    #Set Config Parameters  
    $SiteURL="https://Crescent.sharepoint.com/sites/Marketing"  
    $FolderRelativeURL="/sites/Marketing/Shared Documents/2018"  
        
    #Get Credentials to connect  
    $Cred= Get-Credential  
        
    #Call the function to Get Folder Permissions  
    Get-SPOFolderPermission $SiteURL $FolderRelativeURL  
    

    Test result on my site:
    275889-image.png

    This script generates a folder permissions report. If you need to export these permission settings to a CSV file, you can simply use:

    Get-SPOFolderPermission $SiteURL $FolderRelativeURL | Export-CSV "C:\Temp\FolderPermissions.csv" -NoTypeInformation  
    

    275965-image.png

    ----------

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.