Automate Twilio Integration Tasks from PowerShell



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 Cmdlets for Twilio 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 Twilio.

PowerShell Cmdlets or ADO.NET Provider?

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

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.

PowerShell

  1. Install the module:

    Install-Module TwilioCmdlets
  2. Connect:

    $twilio = Connect-Twilio -AccountSid "$AccountSid" -AuthToken "$AuthToken"
  3. Search for and retrieve data:

    $starttime = "1/1/2016" $calls = Select-Twilio -Connection $twilio -Table "Calls" -Where "StartTime = `'$StartTime`'" $calls

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

    $calls = Invoke-Twilio -Connection $twilio -Query 'SELECT * FROM Calls WHERE StartTime = @StartTime' -Params @{'@StartTime'='1/1/2016'}

ADO.NET

  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

PowerShell

Update-Twilio -Connection $Twilio -Columns @('To','Duration') -Values @('MyTo', 'MyDuration') -Table Calls -Id "MySid"

ADO.NET

$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

PowerShell

Add-Twilio -Connection $Twilio -Table Calls -Columns @("To", "Duration") -Values @("MyTo", "MyDuration")

ADO.NET

$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

PowerShell

Remove-Twilio -Connection $Twilio -Table "Calls" -Id "MySid"

ADO.NET

$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.