In this blog, you will see how to get the external columns by looping through all the lists from 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 GetExternalColumns.ps1.

  1. # Input Parameters
  2. $siteURL="https://c986.sharepoint.com/sites/dev"
  3. # Loop through all the lists and check if the field is external column
  4. Function GetExternalColumns($web)
  5. {
  6. $listColl=Get-PnPList -Web $web
  7. foreach($list in $listColl)
  8. {
  9. $fieldColl=Get-PnPField -List $list.Title -Web $web
  10. foreach($field in $fieldColl)
  11. {
  12. if($field.TypeAsString -eq "BusinessData")
  13. {
  14. write-host -ForegroundColor DarkYellow "List Name: " $list.Title " Field Name: " $field.Title
  15. }
  16. }
  17. }
  18. }
  19. # Get the root web and call the GetExternalColumns function
  20. Function GetRootWeb()
  21. {
  22. $rootWeb=Get-PnPWeb
  23. write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url
  24. GetExternalColumns($rootWeb);
  25. }
  26. # Get the all the sub webs and call the GetExternalColumns function
  27. Function GetSubWebs()
  28. {
  29. $webColl=Get-PnPSubWebs -Recurse
  30. foreach($web in $webColl)
  31. {
  32. write-host -ForegroundColor Magenta "Getting information from the website - " $web.Title " - " $web.Url
  33. GetExternalColumns($web);
  34. }
  35. }
  36. # Connect to SharePoint Online site
  37. Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)
  38. # Call the functions
  39. GetRootWeb
  40. GetSubWebs

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetExternalColumns.ps1 file location

Run the following command,

>.\GetExternalColumns.ps1

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