In this blog, you will see how to get all the lists which have unique permissions from the root site as well as sub sites using PnP PowerShell.
You can download setup files from the releases section of the PnP PowerShell repository.
Copy the below script and paste it in a notepad. Save the file as GetUniquePermissions.ps1.
- # Input Parameters
- $siteURL="https://c986.sharepoint.com/sites/dev"
-
- # foLoop through all the lists and check if the list has unique permissions
- Function GetUniquePermissions($web)
- {
- $listColl=Get-PnPList -Web $web -Includes HasUniqueRoleAssignments
- foreach($list in $listColl)
- {
- if($list.HasUniqueRoleAssignments)
- {
- write-host -ForegroundColor Yellow $list.Title " has unique permissions"
- }
- }
- }
-
- # Get the root web and call the GetUniquePermissions function
- Function GetRootWeb()
- {
- $rootWeb=Get-PnPWeb
- write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url
- GetUniquePermissions($rootWeb);
- }
-
- # Get the all the sub webs and call the GetUniquePermissions function
- Function GetSubWebs()
- {
- $webColl=Get-PnPSubWebs -Recurse
- foreach($web in $webColl)
- {
- write-host -ForegroundColor Magenta "Getting information from the website - " $web.Title " - " $web.Url
- GetUniquePermissions($web);
- }
- }
-
- # Connect to SharePoint Online site
- Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)
-
- # Call the functions
- GetRootWeb
- GetSubWebs
Open PowerShell window and run the following command.
folderlocation – GetUniquePermissions.ps1 file location
Run the following command
- >.\GetUniquePermissions.ps1
Thus in this blog, you saw how to get all the lists which have unique permissions from the SharePoint online site using PnP PowerShell.