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.

  1. # Input Parameters
  2. $siteURL="https://c986.sharepoint.com/sites/dev"
  3. # foLoop through all the lists and check if the list has unique permissions
  4. Function GetUniquePermissions($web)
  5. {
  6. $listColl=Get-PnPList -Web $web -Includes HasUniqueRoleAssignments
  7. foreach($list in $listColl)
  8. {
  9. if($list.HasUniqueRoleAssignments)
  10. {
  11. write-host -ForegroundColor Yellow $list.Title " has unique permissions"
  12. }
  13. }
  14. }
  15. # Get the root web and call the GetUniquePermissions function
  16. Function GetRootWeb()
  17. {
  18. $rootWeb=Get-PnPWeb
  19. write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url
  20. GetUniquePermissions($rootWeb);
  21. }
  22. # Get the all the sub webs and call the GetUniquePermissions function
  23. Function GetSubWebs()
  24. {
  25. $webColl=Get-PnPSubWebs -Recurse
  26. foreach($web in $webColl)
  27. {
  28. write-host -ForegroundColor Magenta "Getting information from the website - " $web.Title " - " $web.Url
  29. GetUniquePermissions($web);
  30. }
  31. }
  32. # Connect to SharePoint Online site
  33. Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)
  34. # Call the functions
  35. GetRootWeb
  36. GetSubWebs
Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetUniquePermissions.ps1 file location

Run the following command

  1. >.\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.