I have this script to loop through all site collections >> and all document libraries >> then list the folders in this format "Site Name >> List Name >> Folder Name":
$AdminUrl = "https://*****-admin.sharepoint.com/"
Connect-PnPOnline -Url $AdminUrl -Interactive
#sharepoint online get all site collections PowerShell
$SiteColl = Get-PnPTenantSite
#sharepoint online PowerShell iterate through all site collections
ForEach($Site in $SiteColl)
{
Connect-PnPOnline -Url $Site.Url -Interactive
$Webs = Get-PnPSubWeb -Recurse -IncludeRootWeb
#Get All document libraries
ForEach($Web in $Webs)
{
$DocumentLibraries = Get-PnPList -Web $Web | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Title -ne "Site Assets" -and $_.Hidden -eq $false}
#Iterate through each document library
ForEach($Library in $DocumentLibraries)
{
$f = Get-PnPFolder -List $Library
ForEach($folder in $f)
{
Write-Host $Site.Title " --> " $Library.Title " --> " $folder.Name
}
}
}
}
but the issue I am facing is that Get-PnPFolder -List $Library
will get all the main folders and sub-folders. So how can I restrict this command to only get the main folders (first level folders) without sub-folders?