Skip to content
January 13, 2021 / kiranpatils

PowerShell script to delete wrong Solr Config using Search Stax API


I’m a big fan of SearchStax as it removes all challenges to install, configure and manage Solr and let experts do experts job!

To set up Solr Collections: I always prefer to use Search Stax Plugin:

I made a mistake once where I had a typo in my config.yml and It uploaded config with the wrong name. (Garbage IN, Garbage OUT) Which I wanted to delete. But there was no way to do this via the plugin. So, I had to write a power shell using Search Stax API to do it and thought to share it with you!


Disclaimer: I’m not yet proficient in Powershell. So, feel free to modify this script if you are Powershell NINJA!

You need to provide few values in the script and you should be good!

# "Please provide authentication information."
$uname = Read-Host Prompt 'Username – '
$password = Read-Host AsSecureString Prompt 'Password – '
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Write-Host "Asking for an authorization token for $uname"
$body = @{
Remove-Variable PASSWORD
$body = $body | ConvertTo-Json
try {
$token = Invoke-RestMethod uri "" Method Post Body $body ContentType 'application/json'
$token = $token.token
Remove-Variable body
Write-Host "Obtained token" $token
$searchstaxUrl = ''
$NAME = 'sitecore_sitecore' # <- CHANGE YOUR VALUE HERE
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Token $token")
#Delete Config
$RESULTS = Invoke-RestMethod Method Delete Headers $headers `
uri "$ACCOUNT/deployment/$uid/zookeeper-config/$NAME/"
$RESULTS = $RESULTS | ConvertTo-Json
#return $token
} catch {
Write-Error Message "Unable to get Auth Token. Error was: $_" ErrorAction Stop

You can find API Documentation from here :

Leave a Reply

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

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

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

<span>%d</span> bloggers like this: