ps1.asciidoc 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. [role="xpack"]
  2. [testenv="platinum"]
  3. [[sql-client-apps-ps1]]
  4. === Microsoft PowerShell
  5. [quote, https://docs.microsoft.com/en-us/powershell/scripting/powershell-scripting]
  6. ____
  7. https://docs.microsoft.com/en-us/powershell/[PowerShell] is a task-based command-line shell and scripting language built on .NET.
  8. ____
  9. PowerShell is available on all recent Windows Desktop OSes. It also has embedded ODBC support, thus offering a quick and accessible way to connect to {es}.
  10. IMPORTANT: Elastic does not endorse, promote or provide support for this application; for native Elasticsearch integration in this product, please reach out to its vendor.
  11. ==== Prerequisites
  12. * Microsoft PowerShell
  13. * {es-sql} <<sql-odbc, ODBC driver>>
  14. * A preconfigured User or System DSN (see <<dsn-configuration,Configuration>> section on how to configure a DSN).
  15. ==== Writing a script
  16. While putting the following instructions into a script file is not an absolute requirement, doing so will make it easier to extend and
  17. reuse. The following instructions exemplify how to execute a simple SELECT query from an existing index in your {es} instance, using a DSN
  18. configured in advance. Open a new file, `select.ps1`, and place the following instructions in it:
  19. ["source","powershell",subs="attributes,callouts"]
  20. --------------------------------------------
  21. $connectstring = "DSN=Local Elasticsearch;"
  22. $sql = "SELECT * FROM library"
  23. $conn = New-Object System.Data.Odbc.OdbcConnection($connectstring)
  24. $conn.open()
  25. $cmd = New-Object system.Data.Odbc.OdbcCommand($sql,$conn)
  26. $da = New-Object system.Data.Odbc.OdbcDataAdapter($cmd)
  27. $dt = New-Object system.Data.datatable
  28. $null = $da.fill($dt)
  29. $conn.close()
  30. $dt
  31. --------------------------------------------
  32. Now open a PowerShell shell and simply execute the script:
  33. [[apps_excel_exed]]
  34. .Run SQL in PowerShell
  35. image:images/sql/odbc/apps_ps_exed.png[]
  36. // vim: set noet fenc=utf-8 ff=dos sts=0 sw=4 ts=4 tw=138 columns=140