SearchStax Help Center

The SearchStax Help Center Frequently Asked Questions page includes FAQs about SearchStax Managed Search, our hosted Apache Solr Cloud service.

Basic Auth Credentials in PowerShell

SearchStax Managed Search service clients 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 = ""
$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.


Do not hesitate to contact the SearchStax Support Desk.

Return to Frequently Asked Questions.