SearchStax

The SearchStax® Frequently Asked Questions page includes the following approved question and answer about our Apache Solr Cloud services.


Basic Auth Credentials in PowerShell

Solr Cloud users who manage their systems through PowerShell scripts quickly discover that PowerShell’s Invoke-RestMethod is not friendly to the usual method of passing the Basic Auth username and password to Solr.

For instance, the following simple query works from cURL and from a browser address window by inserting the Basic Auth credentials directly into the query URL:

https://user:password@<Solr Endpoint><Collection>/select?q=:&wt=json

but the same URL produces a Error 401: Unauthorized Request error in PowerShell.

The following PowerShell snippet executes a simple /select query against a Solr deployment that has been secured with Solr Basic Auth by wrapping the username and password in a PSCredential object:

$SOLR = "https://ss123456-h9513225-us-west-1-aws.searchstax.com/solr/"
$COLL = "xxxxx"    #Name of collection to search
$USER = "xxxxx"    #Solr Basic Auth username
$PASS = "xxxxx"    #Solr Basic Auth password

$SECPASS = ConvertTo-SecureString $PASS -AsPlainText -Force
$CRED = New-Object System.Management.Automation.PSCredential ($USER, $SECPASS)

$queryresults = Invoke-RestMethod -cred $CRED -uri "${SOLR}${COLL}/select?q=*:*&wt=json"

For more information, see Adding Credential Support to PowerShell Functions.


We love to answer questions!

Please contact the SearchStax Support Desk immediately if you have any question about Solr Cloud deployments.

Return to Frequently Asked Questions.