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.
- # Input Parameters
- $siteURL="https://c986.sharepoint.com/sites/dev"
-
- # Loop through all the lists and check if the field is external column
- Function GetExternalColumns($web)
- {
- $listColl=Get-PnPList -Web $web
- foreach($list in $listColl)
- {
- $fieldColl=Get-PnPField -List $list.Title -Web $web
- foreach($field in $fieldColl)
- {
- if($field.TypeAsString -eq "BusinessData")
- {
- write-host -ForegroundColor DarkYellow "List Name: " $list.Title " Field Name: " $field.Title
- }
- }
- }
- }
-
- # Get the root web and call the GetExternalColumns function
- Function GetRootWeb()
- {
- $rootWeb=Get-PnPWeb
- write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url
- GetExternalColumns($rootWeb);
- }
-
- # Get the all the sub webs and call the GetExternalColumns function
- Function GetSubWebs()
- {
- $webColl=Get-PnPSubWebs -Recurse
- foreach($web in $webColl)
- {
- write-host -ForegroundColor Magenta "Getting information from the website - " $web.Title " - " $web.Url
- GetExternalColumns($web);
- }
- }
-
- # Connect to SharePoint Online site
- Connect-PnPOnline –Url $siteURL –Credentials (Get-Credential)
-
- # Call the functions
- GetRootWeb
- GetSubWebs
Open PowerShell window and run the following command.
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.