Please follow below tips to troubleshoot the issue.
1.Get items by paging to avoid returning more than 5000 items at a time. Use $batchSize parament in the PNP PowerShell.
$batchSize = 1000
$items = @()
$batch = Get-PnPListItem -List "YourListName" -PageSize $batchSize
while ($batch -ne $null) {
$items += $batch
$batch = $batch.Skip($batchSize).Take($batchSize)
}
2.Create indexed columns in the document library.
Go to SharePoint library settings -> In the Columns section, click Indexed columns -> Create a new index.
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.