Ready to get started?

Download a free trial of the SingleStore Data Provider to get started:

 Download Now

Learn more:

SingleStore Icon SingleStore ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with SingleStore.

Automate SingleStore Integration Tasks from PowerShell



Are you in search of a quick and easy way to access SingleStore data from PowerShell? This article demonstrates how to utilize the SingleStore Cmdlets for tasks like connecting to SingleStore data, automating operations, downloading data, and more.

The CData Cmdlets for SingleStore are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to SingleStore.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to SingleStore, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete SingleStore data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for SingleStore. To access SingleStore data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for SingleStore.

Once you have acquired the necessary connection properties, accessing SingleStore data in PowerShell can be enabled in three steps.

The following connection properties are required in order to connect to data.

  • Server: The host name or IP of the server hosting the SingleStore database.
  • Port: The port of the server hosting the SingleStore database.
  • Database (Optional): The default database to connect to when connecting to the SingleStore Server. If this is not set, tables from all databases will be returned.

Connect Using Standard Authentication

To authenticate using standard authentication, set the following:

  • User: The user which will be used to authenticate with the SingleStore server.
  • Password: The password which will be used to authenticate with the SingleStore server.

Connect Using Integrated Security

As an alternative to providing the standard username and password, you can set IntegratedSecurity to True to authenticate trusted users to the server via Windows Authentication.

Connect Using SSL Authentication

You can leverage SSL authentication to connect to SingleStore data via a secure session. Configure the following connection properties to connect to data:

  • SSLClientCert: Set this to the name of the certificate store for the client certificate. Used in the case of 2-way SSL, where truststore and keystore are kept on both the client and server machines.
  • SSLClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
  • SSLClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
  • SSLClientCertType: The certificate type of the client store.
  • SSLServerCert: The certificate to be accepted from the server.

Connect Using SSH Authentication

Using SSH, you can securely login to a remote machine. To access SingleStore data via SSH, configure the following connection properties:

  • SSHClientCert: Set this to the name of the certificate store for the client certificate.
  • SSHClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
  • SSHClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
  • SSHClientCertType: The certificate type of the client store.
  • SSHPassword: The password that you use to authenticate with the SSH server.
  • SSHPort: The port used for SSH operations.
  • SSHServer: The SSH authentication server you are trying to authenticate against.
  • SSHServerFingerPrint: The SSH Server fingerprint used for verification of the host you are connecting to.
  • SSHUser: Set this to the username that you use to authenticate with the SSH server.

PowerShell

  1. Install the module:

    Install-Module SingleStoreCmdlets
  2. Connect:

    $singlestore = Connect-SingleStore -User "$User" -Password "$Password" -Database "$Database" -Server "$Server" -Port "$Port"
  3. Search for and retrieve data:

    $shipcountry = "USA" $orders = Select-SingleStore -Connection $singlestore -Table "Orders" -Where "ShipCountry = `'$ShipCountry`'" $orders

    You can also use the Invoke-SingleStore cmdlet to execute SQL commands:

    $orders = Invoke-SingleStore -Connection $singlestore -Query 'SELECT * FROM Orders WHERE ShipCountry = @ShipCountry' -Params @{'@ShipCountry'='USA'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SingleStore\lib\System.Data.CData.SingleStore.dll")
  2. Connect to SingleStore:

    $conn= New-Object System.Data.CData.SingleStore.SingleStoreConnection("User=myUser;Password=myPassword;Database=NorthWind;Server=myServer;Port=3306;") $conn.Open()
  3. Instantiate the SingleStoreDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT ShipName, ShipCity from Orders" $da= New-Object System.Data.CData.SingleStore.SingleStoreDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.shipname $_.shipcity }

Update SingleStore Data

PowerShell

Update-SingleStore -Connection $SingleStore -Columns @('ShipName','ShipCity') -Values @('MyShipName', 'MyShipCity') -Table Orders -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SingleStore.SingleStoreCommand("UPDATE Orders SET ShipCountry='USA' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SingleStore.SingleStoreParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert SingleStore Data

PowerShell

Add-SingleStore -Connection $SingleStore -Table Orders -Columns @("ShipName", "ShipCity") -Values @("MyShipName", "MyShipCity")

ADO.NET

$cmd = New-Object System.Data.CData.SingleStore.SingleStoreCommand("INSERT INTO Orders (ShipCountry) VALUES (@myShipCountry)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SingleStore.SingleStoreParameter("@myShipCountry","USA"))) $cmd.ExecuteNonQuery()

Delete SingleStore Data

PowerShell

Remove-SingleStore -Connection $SingleStore -Table "Orders" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.SingleStore.SingleStoreCommand("DELETE FROM Orders WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.SingleStore.SingleStoreParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()