Ready to get started?

Learn more about the CData ADO.NET Provider for DoubleClick or download a free trial:

Download Now

Automate Google Campaign Manager Integration Tasks from PowerShell

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

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

Cmdlets or ADO.NET?

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

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

Google Campaign Manager uses the OAuth authentication standard. The data provider facilitates OAuth in various ways as described below. The following OAuth flow requires the authenticating user to interact with DoubleClick Campaign Manager, using the browser. You can also use a service account to authenticate.

For authentication guides, see the Getting Started section of the data provider help documentation.

PowerShell

  1. Install the module:

    Install-Module GoogleCMCmdlets
  2. Connect:

    $googlecm = Connect-GoogleCM -UserProfileID "$UserProfileID"
  3. Search for and retrieve data:

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

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

    $campaignperformance = Invoke-GoogleCM -Connection $googlecm -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 Campaign Manager\lib\System.Data.CData.GoogleCM.dll")
  2. Connect to Google Campaign Manager:

    $conn= New-Object System.Data.CData.GoogleCM.GoogleCMConnection("UserProfileID=MyUserProfileID;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the GoogleCMDataAdapter, execute an SQL query, and output the results:

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

Update Google Campaign Manager Data

PowerShell

Update-GoogleCM -Connection $GoogleCM -Columns @('Clicks','Device') -Values @('MyClicks', 'MyDevice') -Table CampaignPerformance -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GoogleCM.GoogleCMCommand("UPDATE CampaignPerformance SET Device='Mobile devices with full browsers' WHERE Id = @myId", $conn) $cmd.Parameters.Add(new System.Data.CData.GoogleCM.GoogleCMParameter("@myId","10456255-0015501366")) $cmd.ExecuteNonQuery()

Insert Google Campaign Manager Data

PowerShell

Add-GoogleCM -Connection $GoogleCM -Table CampaignPerformance -Columns @("Clicks", "Device") -Values @("MyClicks", "MyDevice")

ADO.NET

$cmd = New-Object System.Data.CData.GoogleCM.GoogleCMCommand("INSERT INTO CampaignPerformance (Device) VALUES (@myDevice)", $conn) $cmd.Parameters.Add(new System.Data.CData.GoogleCM.GoogleCMParameter("@myDevice","Mobile devices with full browsers")) $cmd.ExecuteNonQuery()

Delete Google Campaign Manager Data

PowerShell

Remove-GoogleCM -Connection $GoogleCM -Table "CampaignPerformance" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GoogleCM.GoogleCMCommand("DELETE FROM CampaignPerformance WHERE Id=@myId", $conn) $cmd.Parameters.Add(new System.Data.CData.GoogleCM.GoogleCMParameter("@myId","001d000000YBRseAAH")) $cmd.ExecuteNonQuery()