Ready to get started?

Download a free trial of the DoubleClick (DFP) Data Provider to get started:

 Download Now

Learn more:

DoubleClick For Publishers Icon DoubleClick (DFP) ADO.NET Provider

An easy-to-use database-like interface for .NET applications access to live DoubleClick For Publishers data (Companies, Contacts, Placements, Users, and more).

Automate Google Ad Manager Integration Tasks from PowerShell



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

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

PowerShell Cmdlets or ADO.NET Provider?

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

Once you have acquired the necessary connection properties, accessing Google Ad Manager data in PowerShell can be enabled in three steps.

Google Ads Manager uses the OAuth authentication standard. You can authorize the data provider to access Google Ads Manager as an individual user or with a service account that you create in the Google APIs Console. See the Getting Started section in the data provider help documentation for an authentication guide.

PowerShell

  1. Install the module:

    Install-Module GoogleAdsManagerCmdlets
  2. Connect:

    $googleadsmanager = Connect-GoogleAdsManager
  3. Search for and retrieve data:

    $id = "2112976978" $orders = Select-GoogleAdsManager -Connection $googleadsmanager -Table "Orders" -Where "Id = `'$Id`'" $orders

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

    $orders = Invoke-GoogleAdsManager -Connection $googleadsmanager -Query 'SELECT * FROM Orders WHERE Id = @Id' -Params @{'@Id'='2112976978'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for DoubleClick (DFP)\lib\System.Data.CData.GoogleAdsManager.dll")
  2. Connect to Google Ad Manager:

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

    $sql="SELECT Id, Name from Orders" $da= New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.name }

Update Google Ad Manager Data

PowerShell

Update-GoogleAdsManager -Connection $GoogleAdsManager -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Orders -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerCommand("UPDATE Orders SET Id='2112976978' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert Google Ad Manager Data

PowerShell

Add-GoogleAdsManager -Connection $GoogleAdsManager -Table Orders -Columns @("Id", "Name") -Values @("MyId", "MyName")

ADO.NET

$cmd = New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerCommand("INSERT INTO Orders (Id) VALUES (@myId)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerParameter("@myId","2112976978"))) $cmd.ExecuteNonQuery()

Delete Google Ad Manager Data

PowerShell

Remove-GoogleAdsManager -Connection $GoogleAdsManager -Table "Orders" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerCommand("DELETE FROM Orders WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()