1

I'm attempting to streamline the development environment setup process for a large development team. A lot of the setup process is already automated, e.g. we automatically create a Solr Docker container with all the necessary cores.

We make heavy use of indexes and would prefer to avoid having to ask/demo to the developer to manually rebuild their indexes from the Sitecore Control panel.

I could rebuild manually, or via a Sitecore scheduled task but how can I script a Solr index rebuild, ideally from Windows Powershell?

2
  • you can create a page (rebuildindex.aspx?your-params) that will do indexing and you can call it using powershell script. Commented Sep 17, 2019 at 10:04
  • i can use this script inside Powershell IDE module in Sitecore instance. But if we are on powershell IDE outside of sitecore, then the [contentsearchmanager] is not recognized. Any solution to that How to run Powershell scripts to rebuild indexes outside sitecore?
    – Nick
    Commented Jan 3, 2020 at 23:29

1 Answer 1

5

To rebuild indexes from sitecore powershell you can use below script which will re-index all indexes one by one

using namespace Sitecore.ContentSearch

$indexes = [ContentSearchManager]::Indexes

foreach($index in $indexes){
    Write-Host "Re-indexing started " $index.Name
    $index.Rebuild([IndexingOptions]::ForcedIndexing);
    Write-Host "Re-indexing Finished" $index.Name    
}

If you want to rebuild indexes using Windows Powershell only then you should enable remoting services first and then execute script

You can refer this link for enabling remoting services - https://sitecore.stackexchange.com/a/2665/1606

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.