Hello @IT SUPPORT ,
You can run the below command to get all folders:
#Treat the folder as item, and the item attribute is Folder (FileSystemObjectType -eq "Folder")
$Folders = Get-PnPListItem -List $List -PageSize 500 -Fields FileLeafRef | Where {$_.FileSystemObjectType -eq "Folder"}
For example: PnP PowerShell to Get All Folders from a SharePoint Online Document Library
#Parameters
$SiteURL = "https://tenant.sharepoint.com/sites/sitename"
$ListName = "libraryname"
$CSVPath = "C:\Temp\Folders.csv"
$FoldersInventory = @()
#Connect to Site
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#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
Thanks,
Echo Du
================================
If an Answer is helpful, please click "Accept Answer" and upvote it.
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.