Please run following PowerShell.
#Parameters
$SiteURL = "https://tenant.sharepoint.com/sites/emilytestcom"
$ListName = "doc"
$CSVPath = "C:\Folders.csv"
$FoldersInventory = @()
#Connect to Site
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the List
$List = Get-PnPList -Identity $ListName
#Get all Folders from List - with progress bar
$global:counter = 0;
$Folders = Get-PnPListItem -List $List -PageSize 500 -Fields FileLeafRef -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete ($global:Counter / ($List.ItemCount) * 100) -Activity "Getting Folders from List:" -Status "Processing Items $global:Counter to $($List.ItemCount)";} | Where {$_.FileSystemObjectType -eq "Folder"}
#Iterate through all folders in the list
$Folders | ForEach-Object {
#Collect Folder data
$FoldersInventory += [PSCustomObject] @{
FolderName = $_.FieldValues.FileLeafRef
URL = $_.FieldValues.FileRef
}
}
$FoldersInventory
$FoldersInventory | Export-Csv -Path $CSVPath -NoTypeInformation
Result:
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.