SOLVED

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

%3CLINGO-SUB%20id%3D%22lingo-sub-752488%22%20slang%3D%22en-US%22%3EBest%20way%20to%20run%20Get-PNPRecycleBInItems%20against%20multiple%20OneDrives%20and%20with%202FA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-752488%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20been%20asked%20to%20audit%20the%20retention%20policies%20applied%20to%20bunch%20of%20test%20user's%20ODFB%20document%20libraries.%26nbsp%3B%20%26nbsp%3BHence%2C%20looking%20to%20review%20the%20recycle%20bins%20of%20each%20user%26nbsp%3B%20(%20I%20think%20the%20primary%20bin%20is%20scoped%20to%20the%20site%20and%20the%20secondary%20is%20at%20the%20site%20collection%20level)%20.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewith%20this%20in%20mind%20I%26nbsp%3B%20am%20currently%20using%20the%20snippet%20below%2C%20in%20that%20I%20am%20trying%20to%20get%20around%20the%20issue%20when%20my%20first%202FA%20connection%20goes%20through%20ok%20but%20subsequent%20connections%20fail%20because%20I%20presented%20with%20a%20nice%20blank%202FA%20dialog%20and%20VSCode%20just%20freezes.%26nbsp%3B%20Indeed%20I%20end%20up%20having%20to%20to%20restart%20the%20PS%20session%20in%20VSCode.%20If%20there%20is%20a%20better%20way%20to%20parse%20these%20recycle%20bins%2C%20I%20am%20all%20ears!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3E%24retnConnection%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3E%24null%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3Eforeach%3C%2FSPAN%3E%3CSPAN%3E(%3C%2FSPAN%3E%3CSPAN%3E%24auditItem%3C%2FSPAN%3E%20%3CSPAN%3Ein%3C%2FSPAN%3E%20%3CSPAN%3E%24auditItems%3C%2FSPAN%3E%3CSPAN%3E)%20%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%7B%20%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EWrite-Host%3C%2FSPAN%3E%20%3CSPAN%3E%24auditItem.SiteName%3C%2FSPAN%3E%20%3CSPAN%3E%22%20%22%3C%2FSPAN%3E%20%3CSPAN%3E%24auditItem.SiteUrl%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%24ODFBDocumentLibaryUrl%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3E%24ODFBBaseUrl%3C%2FSPAN%3E%20%3CSPAN%3E%2B%3C%2FSPAN%3E%20%3CSPAN%3E%24auditItem.DocumentLibaryUrl%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EWrite-Host%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EForegroundColor%20DarkYellow%20%3C%2FSPAN%3E%3CSPAN%3E%24ODFBDocumentLibraryUrl%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EIf%3C%2FSPAN%3E%3CSPAN%3E%20(%3C%2FSPAN%3E%3CSPAN%3E%24retnConnection%3C%2FSPAN%3E%3CSPAN%3E)%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%7B%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EDisconnect-PnPOnline%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%23%20connect%20to%20the%20user's%20ODFB%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%24retnConnection%3C%2FSPAN%3E%20%3CSPAN%3E%3D%3C%2FSPAN%3E%20%3CSPAN%3EConnect-PnPOnline%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EUrl%20%3C%2FSPAN%3E%3CSPAN%3E%24auditItem.SiteUrl%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EUseWebLogin%20%3C%2FSPAN%3E%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EReturnConnection%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EGet-PnPRecycleBinItem%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3ESecondStage%20%3C%2FSPAN%3E%3CSPAN%3E%7C%3C%2FSPAN%3E%20%3CSPAN%3ESelect-object%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EFirst%20%3C%2FSPAN%3E%3CSPAN%3E100%3C%2FSPAN%3E%3CSPAN%3E%20Title%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E%20DirName%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E%20DeletedByName%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E%20DeletedDate%3C%2FSPAN%3E%3CSPAN%3E%2C%3C%2FSPAN%3E%3CSPAN%3E%20DeletedDateLocalFormatted%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3E%7D%3C%2FSPAN%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-752488%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-753303%22%20slang%3D%22en-US%22%3ERe%3A%20Best%20way%20to%20run%20Get-PNPRecycleBInItems%20against%20multiple%20OneDrives%20and%20with%202FA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753303%22%20slang%3D%22en-US%22%3EWhat%20happens%20if%20you%20add%20-ClearTokenCache%20-SPOManagementShell%20after%20-UseWebLogin%3F%3CBR%20%2F%3E%3CBR%20%2F%3EDoes%20it%20progress%20further%20than%20the%20blank%20screen%3F%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-753342%22%20slang%3D%22en-US%22%3ERe%3A%20Best%20way%20to%20run%20Get-PNPRecycleBInItems%20against%20multiple%20OneDrives%20and%20with%202FA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753342%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F234199%22%20target%3D%22_blank%22%3E%40Steve%20Johnson%3C%2FA%3E%26nbsp%3B%20Thanks%20for%20your%20response.%26nbsp%3B%20I%20have%20always%20wondered%20about%20these%20additional%20parameters.%20Will%20try%20this%20first%20thing%20on%20Monday%26nbsp%3B%20and%20report%20back.%20BTW%20for%20reference%2C%20this%20the%26nbsp%3B%20%22%20white%20screen%20of%20death%22%26nbsp%3B%20%26nbsp%3BI%20have%20been%20encountering.%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F123217i78E7AFDAB44932A1%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%222FA%20Issue%20in%20VSCode.PNG%22%20title%3D%222FA%20Issue%20in%20VSCode.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-753357%22%20slang%3D%22en-US%22%3ERe%3A%20Best%20way%20to%20run%20Get-PNPRecycleBInItems%20against%20multiple%20OneDrives%20and%20with%202FA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-753357%22%20slang%3D%22en-US%22%3ENo%20problem%20at%20all%2C%20it%20sounds%20like%20this%20issue%20which%20a%20few%20others%20have%20come%20up%20against.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fissues%2F1744%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Fissues%2F1744%3C%2FA%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-754434%22%20slang%3D%22en-US%22%3ERe%3A%20Best%20way%20to%20run%20Get-PNPRecycleBInItems%20against%20multiple%20OneDrives%20and%20with%202FA%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-754434%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F234199%22%20target%3D%22_blank%22%3E%40Steve%20Johnson%3C%2FA%3E%26nbsp%3B%20you%20are%20right.%20I%20never%20know%20when%20and%20where%20to%20post%20these%20types%20of%20issue.%26nbsp%3B%20In%20my%20case%20I%20assume%20that%20it%20is%20something%20I%20am%20not%20doing%20correctly%20before%20considering%20an%20SPIssue%20%3Aexpressionless_face%3A%3C%2Fimg%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20some%20findings%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20syntax%20works%20but%20you%20get%20presented%20with%20the%20login%20dialog%20each%20time%20you%20need%20to%20connect.%20%3CEM%3ENote%2C%20you%20can't%20use%20-UseWebLogin%20with%20this%20combinations%20of%20parameters.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3EConnect-PnPOnline%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EUrl%20%3C%2FSPAN%3E%3CSPAN%3E%24auditItem.SiteUrl%3C%2FSPAN%3E%26nbsp%3B%20-%3CSPAN%3EClearTokenCache%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3ESPOManagementShell%26nbsp%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20want%20to%20%3CSTRONG%3Espeedily%20connect%20to%20various%20site%20collections%3C%2FSTRONG%3Ewithout%20always%20being%20presented%20with%20the%20login%20dialog%2C%20then%20I%20recommend%20this%20syntax%20-%20was%20able%20to%20pass%20my%20list%20of%20OneDrive%20Urls%20with%20just%20a%20slight%20pause%20to%20establish%20each%20connection.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CPRE%3E%3CSPAN%3EConnect-PnPOnline%3C%2FSPAN%3E%20%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3EUrl%20%3C%2FSPAN%3E%3CSPAN%3E%24auditItem.SiteUr%3C%2FSPAN%3E%26nbsp%3B%3CSPAN%3E-%3C%2FSPAN%3E%3CSPAN%3ESPOManagementShell%26nbsp%3B%3C%2FSPAN%3E%3C%2FPRE%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

 

Hi 

 

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)

{

Disconnect-PnPOnline

}

# 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
Highlighted
Best Response confirmed by Daniel Westerdale (Regular Contributor)
Solution
What happens if you add -ClearTokenCache -SPOManagementShell after -UseWebLogin?

Does it progress further than the blank screen?
Highlighted

@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

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

https://github.com/SharePoint/PnP-PowerShell/issues/1744
Highlighted

@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