SOLVED

Using Get-PnPListItem without the dreaded ViewTheshold Errors

%3CLINGO-SUB%20id%3D%22lingo-sub-793332%22%20slang%3D%22en-US%22%3EUsing%20Get-PnPListItem%20without%20the%20dreaded%20ViewTheshold%20Errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-793332%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20having%20to%20deal%20with%20a%20large%20number%20of%20Recycle%20Bin%20Items.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ETitle%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Id%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20ItemType%20LeafName%20%20%20%20%20%20%20DirName%0A-----%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20--%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20--------%20--------%20%20%20%20%20%20%20-------%0ADeleteMe1.docx%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20887caa93-7178-4f41-8a28-cbe6e3c36067%20File%20%20%20%20%20DeleteMe1.docx%20personal%2Fdaniel_westerdale_myclient_co_uk%2FDocuments%2FGDPR%2Ftest%3C%2FCODE%3E%3C%2FPRE%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%3CP%3EThis%20is%20all%20well%20and%20good%20but%20try%20located%20the%20file%20once%20this%20has%20been%20restored%20from%20the%20Recycle%20Bin%20in%20order%20to%20set%20the%3CEM%3Ecompliance%20tag%20properties.%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20doesn't%20give%20me%20anything%20I%20can%20use%20to%20locate%20the%20file%20item%20directly%20using%26nbsp%3B%20Get-PnpListItem%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24fileItem%20%3D%20Get-PnPFolderItem%20-FolderSiteRelativeUrl%20%22Documents%2FGDPR%2Ftest%22%20-ItemName%20%20DeleteMe1.docx%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIndeed%2C%20thought%20I%20could%20use%20the%26nbsp%3B%20uniqueID%20as%20shown%20in%20the%20documentation%20...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3EGet-PnpListItem%20-List%20Documents%20-UniqueId%20%24fileItem.UniqueId%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20result%20is%20null%20%3CIMG%20class%3D%22lia-deferred-image%20lia-image-emoji%22%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Fhtml%2Fimages%2Femoticons%2Fcry_40x40.gif%22%20alt%3D%22%3Acry%3A%22%20title%3D%22%3Acry%3A%22%20%2F%3E!%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsing%20another%20approach%2C%26nbsp%3B%20I%20can%20use%20this%20approach%20but%20I%20am%20hitting%20those%20aforementioned%20ViewThreshold%20errors%20.%20As%20my%20friend%26nbsp%3B%40garytrinder%20pointed%20out%20this%20is%20because%20FileLeafRef%20is%20not%20indexed.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24file%24query%20%3D%20%22%3CVIEW%20scope%3D%22RecursiveAll%22%3E%3CQUERY%3E%3CWHERE%3E%3CEQ%3E%3CFIELDREF%20name%3D%22FileLeafRef%22%3E%3C%2FFIELDREF%3E%3CVALUE%20type%3D%22File%22%3E%24filename%3C%2FVALUE%3E%3C%2FEQ%3E%3C%2FWHERE%3E%3C%2FQUERY%3E%3CROWLIMIT%20paged%3D%22TRUE%22%3E4000%3C%2FROWLIMIT%3E%3C%2FVIEW%3E%22%0A%24fileItem%20%3D%20Get-PnPListItem%20-List%20%24Library%20-Query%20%24query%20-PageSize%204000%0A%20%20%20%20%20%20%20%20%20%20%20%20%3C%2FCODE%3E%3C%2FPRE%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%3CP%3EI%20wonder%20if%20there%20is%20a%20clever%20way%20to%20locate%20the%20integer%26nbsp%3B%20Id%26nbsp%3B%20%2C%20so%20I%20can%20go%20directly%20to%20the%20fileItem%2C%20now%20wouldn't%20that%20be%20so%20much%20easier....%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-793332%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-795089%22%20slang%3D%22en-US%22%3ERE%3A%20Using%20Get-PnPListItem%20without%20the%20dreaded%20ViewTheshold%20Errors%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-795089%22%20slang%3D%22en-US%22%3E%3CP%3EWith%20a%20bit%20of%20lateral%20thinking%20.....I%20rewrote%20the%20code%20the%20finds%20the%20file%20.%20No%20recursive%20query%20%3D%20no%20view%20threshold%20errors!%20Rock%20and%20Roll.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%20%24fileFolderItem%20%3D%20Get-PnPFolderItem%20-FolderSiteRelativeUrl%20%24DirectoryRelativePath%20-ItemName%20%24Filename%20%0A%24fileFolderItem.Context.Load(%24fileFolderItem.ListItemAllFields)%0A%24fileFolderItem.Context.ExecuteQuery()%0A%23%20now%20i%20can%20do%20what%20intended%20to%20do..%0A(%24fileFolderItem.ListItemAllFields).SetComplianceTag(......%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Contributor

 

I am having to deal with a large number of Recycle Bin Items.

 

 

 

Title                                Id                                   ItemType LeafName       DirName
-----                                --                                   -------- --------       -------
DeleteMe1.docx                       887caa93-7178-4f41-8a28-cbe6e3c36067 File     DeleteMe1.docx personal/daniel_westerdale_myclient_co_uk/Documents/GDPR/test

 

 

 

 

This is all well and good but try located the file once this has been restored from the Recycle Bin in order to set the compliance tag properties.

 

This doesn't give me anything I can use to locate the file item directly using  Get-PnpListItem

 

 

 

$fileItem = Get-PnPFolderItem -FolderSiteRelativeUrl "Documents/GDPR/test" -ItemName  DeleteMe1.docx

 

 

 

Indeed, thought I could use the  uniqueID as shown in the documentation ...

 

 

Get-PnpListItem -List Documents -UniqueId $fileItem.UniqueId

 

 

The result is null :cry:

 

 

Using another approach,  I can use this approach but I am hitting those aforementioned ViewThreshold errors . As my friend @garytrinder pointed out this is because FileLeafRef is not indexed. 

 

 

$file$query = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>$filename</Value></Eq></Where></Query><RowLimit Paged='TRUE'>4000</RowLimit></View>"
$fileItem = Get-PnPListItem -List $Library -Query $query -PageSize 4000
            

 

 

 

 

I wonder if there is a clever way to locate the integer  Id  , so I can go directly to the fileItem, now wouldn't that be so much easier....

 

 

1 Reply
best response confirmed by Daniel Westerdale (Regular Contributor)
Solution

With a bit of lateral thinking .....I rewrote the code the finds the file . No recursive query = no view threshold errors! Rock and Roll.

 

 

 $fileFolderItem = Get-PnPFolderItem -FolderSiteRelativeUrl $DirectoryRelativePath -ItemName $Filename 
$fileFolderItem.Context.Load($fileFolderItem.ListItemAllFields)
$fileFolderItem.Context.ExecuteQuery()
# now i can do what intended to do..
($fileFolderItem.ListItemAllFields).SetComplianceTag(......