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.
- # Input Parameters
- $siteURL="https://c986.sharepoint.com/sites/dev"
-
- # Loop through all the lists and check if the list is External List
- Function GetExternalLists($web)
- {
- $listColl=Get-PnPList -Web $web
- foreach($list in $listColl)
- {
- if($list.BaseTemplate -eq 600)
- {
- write-host -ForegroundColor Yellow $list.Title " is an external list"
- }
- }
- }
-
- # Get the root web and call the GetExternalLists function
- Function GetRootWeb()
- {
- $rootWeb=Get-PnPWeb
- write-host -ForegroundColor Magenta "Getting information from the website - " $rootWeb.Title " - " $rootWeb.Url
- GetExternalLists($rootWeb);
- }
-
- # Get the all the sub webs and call the GetExternalLists function
- Function GetSubWebs()
- {
- $webColl=Get-PnPSubWebs -Recurse
- foreach($web in $webColl)
- {
- write-host -ForegroundColor Magenta "Getting information from the website - " $web.Title " - " $web.Url
- GetExternalLists($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 – GetExternalLists.ps1 file location
Run the following command
Thus in this blog, you saw how to get all the external lists from SharePoint Online site using PnP PowerShell.