You could use following PowerShell to get information of folders and files such as name, path and size in a document library.
#Parameters
$SiteURL = "https://tenant.sharepoint.com/sites/emilytestnew"
$ListName= "Documents"
$ReportOutput = "C:\Info.csv"
#Connect to SharePoint Online site
Connect-PnPOnline $SiteURL -Interactive
#Array to store results
$Results = @()
#Get all Items from the document library
$List = Get-PnPList -Identity $ListName
$ListItems = Get-PnPListItem -List $ListName -PageSize 5000
$ItemCounter = 0
#Iterate through each item
Foreach ($Item in $ListItems)
{
$Results += New-Object PSObject -Property ([ordered]@{
FileName = $Item.FieldValues.FileLeafRef
RelativeURL = $Item.FieldValues.FileRef
FileSize = $Item.FieldValues.File_x0020_Size
TotalFileSize = $Item.FieldValues.SMTotalSize.LookupId
})
$ItemCounter++
Write-Progress -PercentComplete ($ItemCounter / ($List.ItemCount) * 100) -Activity "Processing Items $ItemCounter of $($List.ItemCount)" -Status "Getting data from Item '$($Item['FileLeafRef'])"
}
#Export the results to CSV
$Results | Export-Csv -Path $ReportOutput -NoTypeInformation
Write-host "Report Exported to CSV Successfully!"
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.