Using Get-PnPListItem without the dreaded ViewTheshold Errors

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)

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 
# now i can do what intended to do..