
Thank you for posting in this community.
Based on the description of your problem, I ran a test. I only added Sites.FullControl.All permission. Then successfully connected to SharePoint Online. The Get-PnPList
command also did not receive any error.
We need to narrow down the problem and try some things. So, please kindly provide more information below to let us work further.
1.Please follow this article to see if you are configuring the Azure AD App correctly. The main thing is to make sure your certificate is configured correctly.
Connect to SharePoint Online using Azure AD App ID from PowerShell
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
2.Since there will be a large number of document libraries in a tenant, we need to iterate through each document library in each site collection and all of its sub-sites to get the file sizes. This operation leads to a lot of loops and consumes a long time. Therefore, it is more appropriate to get the size of the files in all the file libraries in a site. Perhaps this is what is causing your problem.
But you can try combining the following two Power Shells if you want to get the file sizes of all the file libraries in the tenant at once.
PnP PowerShell to Get All Document Libraries in SharePoint Online
#Set Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get all document libraries - Exclude Hidden Libraries
$DocumentLibraries = Get-PnPList | Where-Object {$_.BaseTemplate -eq 101 -and $_.Hidden -eq $false} #Or $_.BaseType -eq "DocumentLibrary"
#Get Document Libraries Name, Default URL, Number of Items,ID
$DocumentLibraries | Select Title, DefaultViewURL, ItemCount, ID
Get File Size for all documents in a SharePoint Online Document Library
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$ListName= "Branding"
$ReportOutput = "C:\Temp\FileSizeRpt.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 500 | Where {$_.FileSystemObjectType -eq "File"}
Write-host "Total Number of Items in the List:"$List.ItemCount
$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 "File Size Report Exported to CSV Successfully!"
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.