Automate Twitter Ads Integration Tasks from PowerShell

Ready to get started?

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

 Download Now

Learn more:

Twitter Ads Icon Twitter Ads ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Twitter Ads.

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

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

PowerShell Cmdlets or ADO.NET Driver?

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

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

All tables require authentication. You must use OAuth to authenticate with Twitter. OAuth requires the authenticating user to interact with Twitter using the browser. For more information, refer to the OAuth section in the Help documentation.


  1. Install the module:

    Install-Module TwitterAdsCmdlets
  2. Connect:

    $twitterads = Connect-TwitterAds
  3. Search for and retrieve data:

    $entity = "ORGANIC_TWEET" $adstats = Select-TwitterAds -Connection $twitterads -Table "AdStats" -Where "Entity = `'$Entity`'" $adstats

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

    $adstats = Invoke-TwitterAds -Connection $twitterads -Query 'SELECT * FROM AdStats WHERE Entity = @Entity' -Params @{'@Entity'='ORGANIC_TWEET'}


  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.TwitterAds.TwitterAdsConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the TwitterAdsDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT EntityId, Entity from AdStats" $da= New-Object System.Data.CData.TwitterAds.TwitterAdsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.entityid $_.entity }