Ready to get started?

Download a free trial of the Google Campaign Manager 360 Data Provider to get started:

 Download Now

Learn more:

Google Campaign Manager 360 Icon Google Campaign Manager 360 ADO.NET Provider

An easy-to-use database-like interface for .NET applications access to live Google Campaign Manager 360 data (Ads, Accounts, Creatives, Orders, and more).

Automate Google Campaign Manager 360 Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Google Campaign Manager 360 data from PowerShell? This article demonstrates how to utilize the Google Campaign Manager 360 Cmdlets for tasks like connecting to Google Campaign Manager 360 data, automating operations, downloading data, and more.

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

PowerShell Cmdlets or ADO.NET Provider?

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

Once you have acquired the necessary connection properties, accessing Google Campaign Manager 360 data in PowerShell can be enabled in three 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 360\lib\System.Data.CData.GoogleCM.dll")
  2. Connect to Google Campaign Manager 360:

    $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 360 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-Object System.Data.CData.GoogleCM.GoogleCMParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert Google Campaign Manager 360 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-Object System.Data.CData.GoogleCM.GoogleCMParameter("@myDevice","Mobile devices with full browsers"))) $cmd.ExecuteNonQuery()

Delete Google Campaign Manager 360 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-Object System.Data.CData.GoogleCM.GoogleCMParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()