How to loop through the Sub site lists and list items using PnP PowerShell

Occasional Contributor

Hi Team,

 

I can able to loop till the subsites, but I am not able to get the current(subsite )Lists/doc lib. the below code is working fine till to get subsite details.

 

$SiteColl = "https://SharePoint-Contose/sites/Test" 
Connect-PnPOnline -Url $SiteColl -UseWebLogin
$WebsCollection = Get-PnPSubWeb
#Iterate through each subsite
 ForEach($Web in $WebsCollection)
{
Write-Host "Working On: " $Web.Url -BackgroundColor DarkGreen
}
}

 

from here I would like to get current web lists/lib please find the code below which I tried.

 

ForEach ($Webs in $SubSites)
{
Write-host $Webs.Url
$PnPListColls = Get-PnPList #("here it get the Root site lists/lib always so updated like below")
$PnPListColls = Get-PnPList -Web $Webs
}
Here is the waring :WARNING: Parameter 'Web' is obsolete. The -Web parameter will be removed in a future release. Use Connect-PnPOnline -Url [subweburl] instead to connect to a subweb

 

WARNING: Parameter 'Web' is obsolete. The -Web parameter will be removed in a future release. Use Connect-PnPOnline -Url [subweburl] instead to connect to a subweb

with this warning it's still getting only Root site list/lib on each loop.

 

I saw this suggestion in other articles

If your suggestion is to Authenticate again for the current web to get list/lib I feel its wrong. because we have already authenticated at the root site, with the authentication we will be able to get Subsites from the root site collection.

 

Any help please on how to get lists/lib for the current Web using the above script.

1 Reply
You have posted on the Microsoft Learn community board which is all about exams, certification and training.
You might get a better response on the Microsoft SharePoint community https://techcommunity.microsoft.com/t5/sharepoint/ct-p/SharePoint