Ready to get started?

Learn more about the Presto PowerShell Cmdlets or download a free trial:

Download Now

Pipe Presto Data to CSV in PowerShell

Use standard PowerShell cmdlets to access Presto tables.

The CData Cmdlets Module for Presto is a standard PowerShell module offering straightforward integration with Presto. Below, you will find examples of using our Presto Cmdlets with native PowerShell cmdlets.

Creating a Connection to Your Presto Data

Set the Server and Port connection properties to connect, in addition to any authentication properties that may be required.

To enable TLS/SSL, set UseSSL to true.

Authenticating with LDAP

In order to authenticate with LDAP, set the following connection properties:

  • AuthScheme: Set this to LDAP.
  • User: The username being authenticated with in LDAP.
  • Password: The password associated with the User you are authenticating against LDAP with.

Authenticating with Kerberos

In order to authenticate with KERBEROS, set the following connection properties:

  • AuthScheme: Set this to KERBEROS.
  • KerberosKDC: The Kerberos Key Distribution Center (KDC) service used to authenticate the user.
  • KerberosRealm: The Kerberos Realm used to authenticate the user with.
  • KerberosSPN: The Service Principal Name for the Kerberos Domain Controller.
  • KerberosKeytabFile: The Keytab file containing your pairs of Kerberos principals and encrypted keys.
  • User: The user who is authenticating to Kerberos.
  • Password: The password used to authenticate to Kerberos.

$conn = Connect-Presto  -Server "$Server" -Port "$Port"

Selecting Data

Follow the steps below to retrieve data from the Customer table and pipe the result into to a CSV file:

Select-Presto -Connection $conn -Table Customer | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myCustomerData.csv -NoTypeInformation

You will notice that we piped the results from Select-Presto into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.

Deleting Data

The following line deletes any records that match the criteria:

Select-Presto -Connection $conn -Table Customer -Where "Id = 123456789" | Remove-Presto

Inserting and Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Presto, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyCustomerUpdates.csv | %{
  $record = Select-Presto -Connection $Presto -Table Customer -Where ("Id = `'"+$_.Id+"`'")
  if($record){
    Update-Presto -Connection $presto -Table Customer -Columns ("FirstName","LastName") -Values ($_.FirstName, $_.LastName) -Where ("Id = `'"+$_.Id+"`'")
  }else{
    Add-Presto -Connection $presto -Table Customer -Columns ("FirstName","LastName") -Values ($_.FirstName, $_.LastName)
  }
}

As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!