SOLVED

Using Get-PnPListItem without the dreaded ViewTheshold Errors

Iron 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....

 

 

2 Replies
best response confirmed by Daniel Westerdale (Iron 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(......

 

 

For those reading this later on, query and pagesize together will not work.

$fileItem = Get-PnPListItem -List $Library -Query $query -PageSize 4000
will still prompt for the result limit of 5000

Do this in stead:

$fileItem = Get-PnPListItem -List $Library -PageSize 4000
without the query, and filter the results later.
1 best response

Accepted Solutions
best response confirmed by Daniel Westerdale (Iron 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(......

 

 

View solution in original post