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 external lists from a root site as well as sub sites using PnP PowerShell.

You can download the setup files from the releases section of PnP PowerShell repository. Copy the below script and paste it in a Notepad. Save the file as GetExternalLists.ps1.

  1. # Input Parameters  
  2. $siteURL="https://c986.sharepoint.com/sites/dev"  
  3.   
  4. # Loop through all the lists and check if the list is External List  
  5. Function GetExternalLists($web)  
  6. {  
  7.     $listColl=Get-PnPList -Web $web  
  8.     foreach($list in $listColl)  
  9.     {                     
  10.         if($list.BaseTemplate -eq 600)  
  11.         {  
  12.             write-host -ForegroundColor Yellow $list.Title " is an external list"  
  13.         }        
  14.     }      
  15. }  
  16.   
  17. # Get the root web and call the GetExternalLists function  
  18. Function GetRootWeb()  
  19. {  
  20.     $rootWeb=Get-PnPWeb  
  21.     write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url  
  22.     GetExternalLists($rootWeb);  
  23. }  
  24.   
  25. # Get the all the sub webs and call the GetExternalLists 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.         GetExternalLists($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 – GetExternalLists.ps1 file location

Run the following command

  1. >.\GetExternalLists.ps1  

 

Thus in this blog, you saw how to get all the external lists from SharePoint Online site using PnP PowerShell.