Skip to content

Instantly share code, notes, and snippets.

@patrickperrone
Last active November 2, 2017 11:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save patrickperrone/59b8745ee8b8ff9045b5 to your computer and use it in GitHub Desktop.
Save patrickperrone/59b8745ee8b8ff9045b5 to your computer and use it in GitHub Desktop.
This PowerShell script will change your Sitecore instance search provider from Lucene to Solr or vice versa.
function Get-ConfigFileFilter([string]$providerName)
{
return "^.*\." + $providerName + "\.(.+\.)?config.*$"
}
function Set-SCSearchProvider
{
$rootPath = Read-Host "What is the path of your Sitecore instance's website folder?";
$choice = Read-Host "(L)ucene or (S)olr?";
$validInput = $true;
#test that path is valid
If (!(Test-Path -Path $rootPath))
{
Write-Host "The supplied path was invalid or inaccessible." -ForegroundColor Red;
$validInput = $false;
}
#test that choice is valid
ElseIf (($choice -ne "L") -and ($choice -ne "S"))
{
Write-Host "You must choose L or S." -ForegroundColor Red;
$validInput = $false;
}
If ($validInput)
{
If (($choice -eq "L"))
{
Write-Host "Set to Lucene." -ForegroundColor Yellow;
$selectedProvider = "Lucene";
$deselectedProvider = "Solr";
}
ElseIf (($choice -eq "S"))
{
Write-Host "Set to Solr." -ForegroundColor Yellow;
$selectedProvider = "Solr";
$deselectedProvider = "Lucene";
}
#enumerate all config files to be enabled
$regexp = Get-ConfigFileFilter $selectedProvider
$filesToEnable = Get-ChildItem -Recurse -File -Path $rootPath | Where-Object { $_.FullName -match $regexp }
foreach ($file in $filesToEnable)
{
Write-Host $file.Name;
if (($file.Extension -ne ".config"))
{
$newFileName = [io.path]::GetFileNameWithoutExtension($file.FullName);
$newFile = Rename-Item -Path $file.FullName -NewName $newFileName -PassThru;
Write-Host "-> " $newFile.Name -ForegroundColor Green;
}
}
#enumerate all config files to be disabled
$regexp = Get-ConfigFileFilter $deselectedProvider
$filesToDisable = Get-ChildItem -Recurse -File -Path $rootPath | Where-Object { $_.FullName -match $regexp }
foreach ($file in $filesToDisable)
{
Write-Host $file.Name;
if ($file.Extension -eq ".config")
{
$newFileName = $file.Name + ".disabled";
$newFile = Rename-Item -Path $file.FullName -NewName $newFileName -PassThru;
Write-Host "-> " $newFile.Name -ForegroundColor Green;
}
}
}
}
Set-SCSearchProvider
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment