0
$query = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef 
          Name='FileLeafRef'/><Value Type='File'>$filename</Value></Eq>
        </Where></Query></View>"
        $fileItem = Get-PnPListItem -List Documents -Query $query



Get-PnPListItem : The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator.
RestoreRecycleBinFile.PS1:121 char:25
+             $fileItem = Get-PnPListItem -List Documents -Query $query

Now I believe I can set a Rowlimit after the delimiting Query tag however, I think would require me to index the files on each user's OneDrive . That scares me! However, even if this is not required, I still need to foreach loop the view output pages and then foreach: parse each item within the page .

<RowLimit Paged="TRUE">5000</RowLimit>

Update: even this rewrite still hits the same error - the where clause seems to break the Rowlimit 😫

function FindFileItemPaged($Library) {

        ## Page Position
    $position = $null

    # the Rowlimt and PageSize has absolutely no affect !!!!!
    $query = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='File'>$filename</Value></Eq></Where></Query><RowLimit Paged='TRUE'>5000</RowLimit></View>"
    $ctx = Get-PnPContext     

    $list = Get-PnPList -Identity $Library
    ##  the file we want
    $fileItem  = $null
    Do{
        $camlQuery = New-Object Microsoft.SharePoint.Client.CamlQuery
        $camlQuery.ListItemCollectionPosition = $position
        $camlQuery.ViewXml = $query
        ## Executing the query

        $currentCollection = $list.GetItems($camlQuery)
        $ctx.Load($currentCollection)
        $ctx.ExecuteQuery()

    ## Getting the position of the previous page
        $position = $currentCollection.ListItemCollectionPosition

    #   check to see if we have found the file we want in this page 
        if ($currentCollection -ne $null)
        {
            $fileItem = $currentCollection
            break # get out of this loop as we are not bothred with the other pages
        }
    }
    # the position of the last page will be Null
    Until($position -eq $null)

    return $fileItem
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.