0

I am using below code to get lists of all subsites. But it is failing after one level of sitecollections. i cant connect with each web using Connect-PnPOnline as it takes too much time. Please suggest how to get lists of all subsites.

$webs= Get-PnPSubWebs -Recurse

foreach ($web in $webs)
{
write-host $web.Url -ForegroundColor Cyan
$sublists = Get-PnPList -web $web 
}
0

Try below mention code

$webs= Get-PnPSubWebs -Recurse

foreach ($web in $webs)
{
   $SubWebs = Get-PnPSubWebs -Identity $web.Title -Recurse
   foreach ($Subweb in $SubWebs)
   {
      write-host $Subweb.Url -ForegroundColor Cyan
      $sublists = Get-PnPList -web $Subweb 
   }
   write-host $web.Url -ForegroundColor Cyan
   $sublists = Get-PnPList -web $web 
}
  • it is giving below error for some of the webs Get-PnPSubWebs : File Not Found. – Adarsh Awasthi Dec 20 '18 at 11:22
  • You need to use this line Connect-PNPonline -Url $subweb.Url -Credentials $cred – Hardik Dec 20 '18 at 12:39
  • still same error coming Get-PnPSubWebs : File Not Found. At line:38 char:19 + $SubSubWebs = Get-PnPSubWebs -Identity $web.Title -Recurse + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : WriteError: (:) [Get-PnPSubWebs], ServerException + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.GetSubWebs – Adarsh Awasthi Dec 21 '18 at 7:19
0

Firstly, you need to make sure your account has proper permission on the site collection.

Then, you can use the following cmdlets to get all subsites of the site collection and all lists of these subsites:

Connect-PnPOnline -Url https://xxx.sharepoint.com/sites/Wendy -Credentials (Get-Credential)

$webs=Get-PnPSubWebs -Recurse
foreach($web in $webs)
{
write-host $web.Url -ForegroundColor Cyan
$sublists = Get-PnPList -web $web 
$sublists
}

My result is: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.