Microsoft PowerShell

You can use the Elasticsearch ODBC driver to access Elasticsearch data from Microsoft PowerShell.

Elastic does not endorse, promote or provide support for this application; for native Elasticsearch integration in this product, please reach out to its vendor.

Prerequisites

Writing a script

While putting the following instructions into a script file is not an absolute requirement, doing so will make it easier to extend and reuse. The following instructions exemplify how to execute a simple SELECT query from an existing index in your Elasticsearch instance, using a DSN configured in advance. Open a new file, select.ps1, and place the following instructions in it:

  1. $connectstring = "DSN=Local Elasticsearch;"
  2. $sql = "SELECT * FROM library"
  3. $conn = New-Object System.Data.Odbc.OdbcConnection($connectstring)
  4. $conn.open()
  5. $cmd = New-Object system.Data.Odbc.OdbcCommand($sql,$conn)
  6. $da = New-Object system.Data.Odbc.OdbcDataAdapter($cmd)
  7. $dt = New-Object system.Data.datatable
  8. $null = $da.fill($dt)
  9. $conn.close()
  10. $dt

Now open a PowerShell shell and simply execute the script:

Run SQL in PowerShellapps ps exed