Automate Google Ads Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Google AdWords ADO.NET Provider

An easy-to-use database-like interface for .NET applications access to live Google AdWords data (Campaigns, AdGroups, Performance, and more).



Are you looking for a quick and easy way to access Google Ads data from PowerShell? We show how to use the Cmdlets for Google Ads and the CData ADO.NET Provider for Google Ads to connect to Google Ads data and synchronize, automate, download, and more.

The CData Cmdlets for Google 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 Google Ads.

Cmdlets or ADO.NET?

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

After obtaining the needed connection properties, accessing Google Ads data in PowerShell consists of three basic steps.

Google uses the OAuth authentication standard. To access Google APIs on behalf on individual users, you can use the embedded credentials or you can register your own OAuth app.

OAuth also enables you to use a service account to connect on behalf of users in a Google Apps domain. To authenticate with a service account, you will need to register an application to obtain the OAuth JWT values.

In addition to the OAuth values, specify the DeveloperToken and ClientCustomerId.

See the "Getting Started" chapter of the help documentation for a guide to using OAuth.

PowerShell

  1. Install the module:

    Install-Module GoogleAdsCmdlets
  2. Connect:

    $googleads = Connect-GAds -DeveloperToken "$DeveloperToken" -ClientCustomerId "$ClientCustomerId"
  3. Search for and retrieve data:

    $device = "'Mobile devices with full browsers'" $campaignperformance = Select-GAds -Connection $googleads -Table "CampaignPerformance" -Where "Device = `'$Device`'" $campaignperformance

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

    $campaignperformance = Invoke-GAds -Connection $googleads -Query 'SELECT * FROM CampaignPerformance WHERE Device = @Device' -Params @{'@Device'=''Mobile devices with full browsers''}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.GoogleAds.GoogleAdsConnection("DeveloperToken=MyDeveloperToken;ClientCustomerId=MyClientCustomerId;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the GoogleAdsDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Device, Clicks from CampaignPerformance" $da= New-Object System.Data.CData.GoogleAds.GoogleAdsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.device $_.clicks }