Powershell Script to uninstall Solr Service and delete Solr instance folder

This script is useful uninstalling Solr when you have multiple  instances of Solr running from different folders in the same machine. In other words, this script does a reverse of https://navansitecorenotes.blogspot.com/2020/06/ps-script-changes-to-run-multiple.html wherein Solr gets installed in a folder specific for that instance. So, use this powershell script  only if your solr is running from a specific folder since it deletes the concerned folder and also the Solr service. 

Uninstall Solr PS Script here

Copy Script from below this line
Param(
$solrVersion = "7.5.0",
$nssmVersion = "2.24",
    $installSubFolder = "instance-8",
    $installFolder = "C:\solr\$installSubFolder",
    $solrSvcName="solr-$installSubFolder-$solrVersion"
)

$svc = Get-Service "$solrSvcName" -ErrorAction SilentlyContinue
if($svc)
{
    Write-Host "Uninstalling Solr service"
    &"$installFolder\nssm-$nssmVersion\win64\nssm.exe" stop "$solrSvcName"
&"$installFolder\nssm-$nssmVersion\win64\nssm.exe" remove "$solrSvcName" confirm
}
else
{
Write-Host "Solr service does not exist!"
}

Write-Host "Deleting Solr Instance Folder"
rm $installFolder -force -recurse -ea ig

Write-Host "Deleted Solr Instance Folder"

Comments

  1. Thanks for sharing, nice post! Post really provice useful information! I would like to share more information on the same. Nextbrick, Inc is a technology services firm that provides consulting services. For over 5 years, NextBrick has worked with onboardings, performance tuning, relevancy tuning and general Apache Solr Consulting Services and Lucidworks Fusion support for enterprise search and e-commerce search solutions for Fortune 500 companies.

    ReplyDelete

Post a Comment

Popular Posts