Add some code around that 3rd-party script to help figure out what's happening:
$mailboxes = Get-EXOMailbox -ResultSize unlimited -RecipientTypeDetails usermailbox
$count = 0
$errors = 0
Write-Host "Will process $($mailboxes.count) mailboxes" -ForegroundColor Yellow
Foreach ($mailbox in $mailboxes) {
Write-Host "Begin processing $($mailbox.UserPrincipalName)" -ForegroundColor Yellow
.\graph-PopulateContactsFromCSV.ps1 -Mailbox $mailbox.UserPrincipalName -ClientSecret $clientSecret -ClientID $clientID -TenantID $tenantID -CSVPath $csvPath
if( -not $? )
{
$msg = $Error[0].Exception.Message
Write-Host "Encountered error during Deleting the Folder. Error Message is $msg. Please check." -ForegroundColor Red
$errors++
}
Write-Host "Finished processing $($mailbox.UserPrincipalName)"
$count++
}
Write-Host "Processed $count mailboxes"
Write-Host "There were $errors errors"
That 3rd-part script is already very noisy. It writes an awful lot of stuff to the console. It must be hard to find any errors in the noise.
If the problem only happens for certain mailboxes, I'd be looking at those mailboxes for the problem.