How do I find all files with many versions using Search?

If you are familiar with SharePoint and Microsoft Search you might have notified the Managed Property “UIVersionStringOWSTEXT”

However, as the name of the Managed Property implies, this property is a Text, which prevents us for using a query like this:

{searchTerms} isdocument:1 pdf UIVersionStringOWSTEXT>10

So how do I find all the files in the tenant that has more than 10 versions???

As usual there are more than one option:

Brute force:

$reducedNumberOfVersions = 10
$query = "contentclass:STS_ListItem_DocumentLibrary"
$searchResults = Submit-PnPSearchQuery -Query $query -Connection $connection -ErrorAction Stop -All -SelectProperties "UIVersionStringOWSTEXT","Path","SPWebUrl"

$counter=0
foreach($searchResult in $searchResults )
{
    write-host "Processing item $($counter) of $($searchResults.Count)"
    $counter++  
    $majorversionnumber = [int]$searchResult.UIVersionStringOWSTEXT
    if( $majorversionnumber -gt $reducedNumberOfVersions)
    {
		#do something 
	}
}

Greb all files in document libraries, cast the “UIVersionStringOWSTEXT” to an Int and compare against the cut off value.

Another, more elegant solution, is to “cast” the UIVersionStringOWSTEXT text value to a number within the search index. This can be done by mapping the “OWS_Q_TEXT__UIVERSIONSTRING” crawled property to a RefinableDecimal:

And once the reindexing is done, you can now query like this: RefinableDecimal02>10

The “trick” has proven to be very handy when scanning a tenant for items with many version as it is WAY faster than iterating through each site and library….

#SharingIsCaring

About the Author

Kasper Larsen

Kasper Larsen

Microsoft M365 MVP, Senior Solution Architect at Fellowmind Denmark, Maintainer of the PnP Modern search project, ” If your Information Architecture is lacking, forget all about a good Search or Copilot experience”

Reference:

Larsen, K (2025). How do I find all files with many versions using Search?. Available at: How do I find all files with many versions using Search? [Accessed: 16th July 2025].

Share this on...

Rate this Post:

Share:

Topics:

SharePoint