top of page

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

Writer: Kasper LarsenKasper Larsen

Updated: Mar 11

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


Comments


30103817

  • Twitter
  • LinkedIn

©2023 by M365thinking. Proudly created with Wix.com

bottom of page