SharePoint Online Powershell | Get Document Library Folders & Sub Folders

122013-image.png

Like:

Please provide me a powershell script to run

SharePoint

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.

10,608 questions Sign in to follow SharePoint Server Management

SharePoint Server: A family of Microsoft on-premises document management and storage systems. Management: The act or process of organizing, handling, directing or controlling something.

2,936 questions Sign in to follow Windows Server PowerShell

Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications. PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.

5,504 questions Sign in to follow 0 comments No comments Report a concern I have the same question I have the same question 1 vote Add comment

5 answers

Sort by: Most helpful Most helpful Newest Oldest

Elsie Lu_MSFT 9,796 Reputation points 2021-08-11T02:52:43.43+00:00

Hi @Anonymous , I have found a PowerShell script you can have a try. This script will return users and specific permissions according to the url and folder you specify.

#Function to Get Permissions Applied on a particular Object such as: Web, List, Library, Folder or List Item Function Get-PnPPermissions([Microsoft.SharePoint.Client.SecurableObject]$Object) < Try < #Get permissions assigned to the Folder Get-PnPProperty -ClientObject $Object -Property HasUniqueRoleAssignments, RoleAssignments #Check if Object has unique permissions $HasUniquePermissions = $Object.HasUniqueRoleAssignments #Loop through each permission assigned and extract details $PermissionCollection = @() Foreach($RoleAssignment in $Object.RoleAssignments) < #Get the Permission Levels assigned and Member Get-PnPProperty -ClientObject $RoleAssignment -Property RoleDefinitionBindings, Member #Get the Principal Type: User, SP Group, AD Group $PermissionType = $RoleAssignment.Member.PrincipalType $PermissionLevels = $RoleAssignment.RoleDefinitionBindings | Select -ExpandProperty Name #Remove Limited Access $PermissionLevels = ($PermissionLevels | Where < $_ –ne "Limited Access">) -join "," If($PermissionLevels.Length -eq 0) #Get SharePoint group members If($PermissionType -eq "SharePointGroup") < #Get Group Members $GroupMembers = Get-PnPGroupMembers -Identity $RoleAssignment.Member.LoginName #Leave Empty Groups If($GroupMembers.count -eq 0)ForEach($User in $GroupMembers) < #Add the Data to Object $Permissions = New-Object PSObject $Permissions | Add-Member NoteProperty User($User.Title) $Permissions | Add-Member NoteProperty Type($PermissionType) $Permissions | Add-Member NoteProperty Permissions($PermissionLevels) $Permissions | Add-Member NoteProperty GrantedThrough("SharePoint Group: $($RoleAssignment.Member.LoginName)") $PermissionCollection += $Permissions >> Else < #Add the Data to Object $Permissions = New-Object PSObject $Permissions | Add-Member NoteProperty User($RoleAssignment.Member.Title) $Permissions | Add-Member NoteProperty Type($PermissionType) $Permissions | Add-Member NoteProperty Permissions($PermissionLevels) $Permissions | Add-Member NoteProperty GrantedThrough("Direct Permissions") $PermissionCollection += $Permissions >> #Export Permissions to CSV File $PermissionCollection | Export-CSV $ReportFile -NoTypeInformation Write-host -f Green "`n*** Folder Permission Report Generated Successfully!***" > Catch < write-host -f Red "Error Generating Folder Permission Report!" $_.Exception.Message >> #region ***Parameters*** $SiteURL="https://****.sharepoint.com/sites/TeamMisTest" $ReportFile="C:\Temp\FolderPermissionRptaa.csv" $FolderRelativeURL = "/sites/TeamMisTest/Shared Documents/General" #endregion #Connect to the Site collection Connect-PnPOnline -URL $SiteURL -UseWebLogin #Get the Folder from URL $Folder = Get-PnPFolder -Url $FolderRelativeURL #Call the function to generate permission report Get-PnPPermissions $Folder.ListItemAllFields 

Please remember to specify the URL and folder you want in the code then you can output all users who have permission to this folder to the csv, and you can view the permission level:

 $SiteURL="https://****.sharepoint.com/sites/TeamMisTest" $ReportFile="C:\Temp\FolderPermissionRpt.csv" $FolderRelativeURL = "/sites/TeamMisTest/Shared Documents/General" 

122119-16.jpg

Test Result in my end:
Referenece:
SharePoint Online: PowerShell to Get Folder Permissions 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 the 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.