0

I'll preface this by saying my Powershell knowledge is fairly minimal and this is my first time trying to use PnP, so if there's something about my approach that seems off, please let me know. Currently have a new client with around 500 document libraries that are stored in a subsite (https://clientname.sharepoint.com/clients) that is under the default team site. The goal is to consolidate the files in these libraries within a single new library in a new site (https://clientname.sharepoint.com/sites/companyweb). Currently I'm having issues querying any of the libraries in the subsite via PnP. When I run get-pnplist -identity "https://clientname.sharepoint.com/Clients/libraryname or get-pnplist -identity "https://clientname.sharepoint.com/Clients", I get no output. When I run this code while connected to the base site

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

It does output the expected library names and URLs as expected. Could there be something about the URL formatting that I'm missing?

1 Answer 1

0

The following worked for me.

Import-Module -Name SharePointPnPPowerShellOnline -Verbose

$cred= Get-Credential

#Config Variables
$SiteURL = "https://tenant.sharepoint.com/sites/SiteColl/"
 
#Connect to PnP Online - User this for Personal SPOnline Site
Connect-PnPOnline -Url $SiteURL -Credentials $cred 

#Process the root web First
$rootWeb= Get-PnPWeb

$allLists=@()

#all list/library from the root
$listRoot=Get-PnPList -Web $rootWeb

$allLists=$listRoot

Write-host "Number of list in the root web: " $allLists.Count

#get all sub sites
$subWebs =Get-PnPSubWebs -Recurse


foreach($subweb in $subWebs)
{
   Connect-PnPOnline -Url $subweb.Url -Credentials $cred 

   $lists = Get-PnPList -Web $subweb

   $allLists+=$lists
}

Write-host "Number of list in All Webs: " $allLists.Count
2
  • using "clientname.sharepoint.com" for the SiteURL variable gets me a count of the lists/libraries in the root site, but it doesn't grab anything from the subsites. Running Get-PnPSubwebs and Get-PnPSubWebs -Recurse on their own while connected to the root site results in no output. Using "clientname.sharepoint.com/Clients" does get a count of the libraries though. Oct 6, 2020 at 16:21
  • within foreach{}, in my script, I'm again connecting to the sub-site. Connect-PnPOnline -Url $subweb.Url -Credentials $cred - Are you doing that? Oct 6, 2020 at 17:35

Your Answer

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

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