Automate Twilio Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

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.



Are you looking for a quick and easy way to access Twilio data from PowerShell? We show how to use the Cmdlets for Twilio and the CData ADO.NET Provider for Twilio to connect to Twilio data and synchronize, automate, download, 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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Twilio API, 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.

After obtaining the needed connection properties, accessing Twilio data in PowerShell consists of three basic 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 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 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 System.Data.CData.Twilio.TwilioParameter("@mySid","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()