Best way to run Get-PNPRecycleBInItems against multiple OneDrives and with 2FA

Regular Contributor




I have been asked to audit the retention policies applied to bunch of test user's ODFB document libraries.   Hence, looking to review the recycle bins of each user  ( I think the primary bin is scoped to the site and the secondary is at the site collection level) .


with this in mind I  am currently using the snippet below, in that I am trying to get around the issue when my first 2FA connection goes through ok but subsequent connections fail because I presented with a nice blank 2FA dialog and VSCode just freezes.  Indeed I end up having to to restart the PS session in VSCode. If there is a better way to parse these recycle bins, I am all ears!


$retnConnection = $null

foreach($auditItem in $auditItems)


Write-Host $auditItem.SiteName " " $auditItem.SiteUrl

$ODFBDocumentLibaryUrl = $ODFBBaseUrl + $auditItem.DocumentLibaryUrl

Write-Host -ForegroundColor DarkYellow $ODFBDocumentLibraryUrl

If ($retnConnection)




# connect to the user's ODFB

$retnConnection = Connect-PnPOnline -Url $auditItem.SiteUrl -UseWebLogin -ReturnConnection

Get-PnPRecycleBinItem -SecondStage | Select-object -First 100 Title, DirName, DeletedByName, DeletedDate, DeletedDateLocalFormatted



4 Replies
best response confirmed by Daniel Westerdale (Regular Contributor)
What happens if you add -ClearTokenCache -SPOManagementShell after -UseWebLogin?

Does it progress further than the blank screen?

@Deleted  Thanks for your response.  I have always wondered about these additional parameters. Will try this first thing on Monday  and report back. BTW for reference, this the  " white screen of death"   I have been encountering.2FA Issue in VSCode.PNG

No problem at all, it sounds like this issue which a few others have come up against.

@Deleted  you are right. I never know when and where to post these types of issue.  In my case I assume that it is something I am not doing correctly before considering an SPIssue :expressionless_face:.


I have some findings:


This syntax works but you get presented with the login dialog each time you need to connect. Note, you can't use -UseWebLogin with this combinations of parameters.


Connect-PnPOnline -Url $auditItem.SiteUrl  -ClearTokenCache -SPOManagementShell 


If you want to speedily connect to various site collections without always being presented with the login dialog, then I recommend this syntax - was able to pass my list of OneDrive Urls with just a slight pause to establish each connection.


Connect-PnPOnline -Url $auditItem.SiteUr -SPOManagementShell