I found a code snippet that loops through the files and folders in SharePoint, using PnP PowerShell, and retrieves the count. When I modify the code to also retrieve the last modified date and size for each file and folder, it doesn't work. Below is the code snippet:
#Connect to SharePoint Online
Connect-PnPOnline -Url $SiteUrl -Interactive
#Function to get number of Sub-folder and Files count recursively
Function Get-SPOFolderStats
{
[cmdletbinding()]
param
([Parameter(Mandatory=$true,ValueFromPipeline=$true)][Microsoft.SharePoint.Client.Folder]$Folder)
#Get Sub-folders of the folder
Get-PnPProperty -ClientObject $Folder -Property ServerRelativeUrl, Folders | Out-Null
#Get the SiteRelativeUrl
$Web = Get-PnPWeb -Includes ServerRelativeUrl
$SiteRelativeUrl = $Folder.ServerRelativeUrl -replace "$($web.ServerRelativeUrl)", [string]::Empty
$PNPFile = Get-PnPFolderItem -FolderSiteRelativeUrl $SiteRelativeUrl -ItemType File
$PNPFolder = Get-PnPFolderItem -FolderSiteRelativeUrl $SiteRelativeUrl -ItemType Folder
**[PSCustomObject] @{
Folder = $Folder.Name
Path = $Folder.ServerRelativeUrl
"Item Count" = $PNPFile | Measure-Object | Select-Object -ExpandProperty Count
"Sub-Folder Count" = $PNPFolder | Measure-Object | Select-Object -ExpandProperty Count**
}
#Process Sub-folders
ForEach($SubFolder in $Folder.Folders) {Get-SPOFolderStats -Folder $SubFolder}
}