Automate Twilio Integration Tasks from PowerShell

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

The CData ADO.NET Provider for Twilio is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Twilio.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Twilio; this tutorial shows how to use the Provider to create, retrieve, update, and delete Twilio data.

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

Use the AccountSid and AuthToken connection properties to access data from your account. You obtain your live credentials on your Twilio account dashboard. Click Account -> Account Settings to obtain your test credentials.

  1. Load the provider's assembly:

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

     
    $conn= New-Object System.Data.CData.Twilio.TwilioConnection("AccountSid=MyAccountSid;AuthToken=MyAuthToken;")
    $conn.Open()
    
  3. Instantiate the TwilioDataAdapter, execute an SQL query, and output the results:

    
    $sql="SELECT To, Duration from Calls"
    
    $da= New-Object System.Data.CData.Twilio.TwilioDataAdapter($sql, $conn)
    $dt= New-Object System.Data.DataTable
    $da.Fill($dt)
    
    $dt.Rows | foreach {
    	Write-Host $_.to $_.duration
    }
      

Update Twilio Data


$cmd =  New-Object System.Data.CData.Twilio.TwilioCommand("UPDATE Calls SET StartTime='1/1/2016' WHERE Sid = @mySid", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Twilio.TwilioParameter("@mySid","10456255-0015501366")))
$cmd.ExecuteNonQuery()

Insert Twilio Data


$cmd =  New-Object System.Data.CData.Twilio.TwilioCommand("INSERT INTO Calls (StartTime) VALUES (@myStartTime)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Twilio.TwilioParameter("@myStartTime","1/1/2016")))
$cmd.ExecuteNonQuery()

Delete Twilio Data


$cmd =  New-Object System.Data.CData.Twilio.TwilioCommand("DELETE FROM Calls WHERE Sid=@mySid", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Twilio.TwilioParameter("@mySid","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()

Ready to get started?

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

 Download Now

Learn more:

Twilio Icon Twilio ADO.NET Provider

Complete read-write access to Twilio enables developers to search (Accounts, Applications, Messages, Recordings, etc.), update items, edit customers, and more, from any .NET application.