Friday, October 17, 2014

Retrieve count of documents in Search Index - SharePoint 2013

To retrieve count of  documents in search index, save below script as .ps1 file and run it using powershell


<# 
.SYNOPSIS 
    Script to get the total number of indexed documents  
.DESCRIPTION 
    For the given Search Application, return the total number of indexed documents. 
    This will be the sum of indexed documents for all index partitions. 
.PARAMETER SearchApplication 
    Search application to use.   Multiple SSA's can be specified by 
    piping them in to the script.  In that case the result will be an array 
    of document counts, one for each SSA 
.EXAMPLE 
    Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchIndexedDocumentCount.ps1 
    88123 
.LINK 
http://gallery.technet.microsoft.com/ScriptCenter 
.NOTES 
  File Name : Get-SPEnterpriseSearchIndexedDocumentCount.ps1 
  Author    : Matthew King 
 
#> 
 
[CmdletBinding()] 
param([Parameter(ValueFromPipeline=$True)] 
      [Microsoft.Office.Server.Search.Cmdlet.SearchServiceApplicationPipeBind]$SearchApplication) 
 
Process { 
    $ssa = Get-SPEnterpriseSearchServiceApplication $SearchApplication 
    $topo = Get-SPEnterpriseSearchTopology -SearchApplication $ssa | ? { $_.State -eq 'Active'} 
    $count = 0 
    Get-SPEnterpriseSearchComponent -SearchTopology $topo | ` 
        ? { $_ -is [Microsoft.Office.Server.Search.Administration.Topology.IndexComponent] } | ` 
        Sort-Object IndexPartitionOrdinal -Unique | % { $component = $_ 
            [int]$c = $ssa | Get-SPEnterpriseSearchStatus –HealthReport –Component $component.Name | ` 
                ? { $_.name -match 'number of documents\[' } | % { $_.message } 
            Write-Verbose ("{0} {1} {2} " -$ssa.Name, $component.Name, $c) 
            $count +$c 
    } 
    $count 
}

Reference
https://gallery.technet.microsoft.com/office/Script-to-report-total-88056b1b

No comments: