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