1

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 
}

2 Answers 2

1

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

-1

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 
}
3
  • it is giving below error for some of the webs Get-PnPSubWebs : File Not Found. Commented Dec 20, 2018 at 11:22
  • You need to use this line Connect-PNPonline -Url $subweb.Url -Credentials $cred
    – Hardik
    Commented Dec 20, 2018 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 Commented Dec 21, 2018 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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