0

Is there anyway to get the count of documents where document has not been modified for 30 days? I was thinking of CAML query but is it possible to only get the count? Some list contains hundred of thousands of documents so I will get a thresh hold error. I am only looking for the count. Not sure if keyword query can do it. Just provide the amount of files.

0

You can use a CAML query to get the count of documents. You can use PowerShell to get all the files not modified in recent 30 days and get the count of them. The script below works for a library.

#Config Variables
$SiteURL = "Site URL"
$LibraryName = "Documents"
   
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
 
#Define Query to Filter Files that were modified 30 days ago (or More!)
$Query= "<View Scope='RecursiveAll'>
            <Query>
                <Where>
                    <And>
                        <Lt>
                            <FieldRef Name='Modified' Type='DateTime'/>
                            <Value Type='DateTime' IncludeTimeValue='TRUE'>
                                <Today OffsetDays='-30'/>
                            </Value>
                        </Lt>
                        <Eq>
                            <FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value>
                        </Eq>
                    </And>
                </Where>
            </Query>
        </View>"
 
#Get All Files matching the query
$Files = Get-PnPListItem -List $LibraryName -Query $Query -PageSize 500
Write-host $Files.Length

If you have not install the PNP package before, install it.

Reference: https://www.sharepointdiary.com/2019/04/sharepoint-online-delete-files-older-than-30-days-using-powershell.html

  • But this will retreive all documents right? A big overhead if you just need the count. Some libraries has millions. And wont you get a thresshold exceptions if you have a resultset larger tan 5000 ? – Thomas Segato Sep 16 '20 at 9:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.