Sitecore Powershell Script to reindex a specific item on a specific index

Sometimes you need reindex an item but you don’t want to rebuild the whole index. Here is a handy script that will let you reindex any item on any specific index. You can also add any specific logic and it will index the items for you.

$options = @{} 

[Sitecore.ContentSearch.ContentSearchManager]::Indexes | Foreach-Object { $options.Add($_.Name, $_.Name) } 

$props = @{ 
    Parameters = @( 
        @{Name="indexName"; Title="Choose an index"; Options=$options; Tooltip="Choose one."} 
    ) 
    Title = "Index selector" 
    Description = "Choose an index." 
    Width = 300 
    Height = 300 
    ShowHints = $true 
} 

$result = Read-Variable @props 

if ($result -eq "ok") { 
    $index = [Sitecore.ContentSearch.ContentSearchManager]::GetIndex($indexName) 
} 

Close-Window 
  

Get-ChildItem -path "/sitecore/content/Home/" -language en-Us -Recurse | Where-Object { $_.TemplateName -eq 'Product'  } | ForEach-Object { 

    if([string]::IsNullOrEmpty($_."Any Field")){ 
        write-host $_.Name " SKIPPED" 
    } 
    else{ 
         write-host $_.Name $_.Paths.FullPath 
       [Sitecore.ContentSearch.Maintenance.IndexCustodian]::Refresh($index, [Sitecore.ContentSearch.SitecoreIndexableItem]$_) 
    }      

} 

Hope it helps!

Happy scripting.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s