How To Get All The Lists Which Have Unique Permissions From the Sharepoint Online Site Using PnP PowerShell

In this blog, you will see how to get all the external lists from SharePoint Online site using PnP PowerShell.

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.   
  4. # foLoop through all the lists and check if the list has unique permissions  
  5. Function GetUniquePermissions($web)  
  6. {  
  7.     $listColl=Get-PnPList -Web $web -Includes HasUniqueRoleAssignments     
  8.     foreach($list in $listColl)  
  9.     {    
  10.         if($list.HasUniqueRoleAssignments)  
  11.         {  
  12.             write-host -ForegroundColor Yellow $list.Title " has unique permissions"  
  13.         }        
  14.     }      
  15. }  
  16.   
  17. # Get the root web and call the GetUniquePermissions function  
  18. Function GetRootWeb()  
  19. {  
  20.     $rootWeb=Get-PnPWeb      
  21.     write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url  
  22.     GetUniquePermissions($rootWeb);  
  23. }  
  24.   
  25. # Get the all the sub webs and call the GetUniquePermissions function  
  26. Function GetSubWebs()  
  27. {  
  28.     $webColl=Get-PnPSubWebs -Recurse      
  29.     foreach($web in $webColl)  
  30.     {      
  31.         write-host -ForegroundColor Magenta "Getting information from the website - " $web.Title " - " $web.Url  
  32.         GetUniquePermissions($web);  
  33.     }  
  34. }  
  35.   
  36. Connect to SharePoint Online site  
  37. Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)  
  38.   
  39. # Call the functions  
  40. GetRootWeb  
  41. 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.