Close

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.

Sitecore Platform Inspection – Part 1

Sometimes our Sitecore instance suffers from performance issues, cumbersome content managing process, limitations, etc. so there is a need we need to review our solution and evaluate how well it is implemented. In these blog series I will provide some guidance on how to perform a  Sitecore platform inspection to evaluate the architecture of a solution measured against current Sitecore best practices

Read More »

Back to top