![]() |
VOOZH | about |
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.
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.
Install the module:
Install-Module GoogleAdsManagerCmdlets
Connect:
$googleadsmanager = Connect-GoogleAdsManager -InitiateOAuth "$InitiateOAuth"
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'}
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")
Connect to Google Ad Manager:
$conn= New-Object System.Data.CData.GoogleAdsManager.GoogleAdsManagerConnection("InitiateOAuth=GETANDREFRESH;")
$conn.Open()
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-GoogleAdsManager -Connection $GoogleAdsManager -Columns @('Id','Name') -Values @('MyId', 'MyName') -Table Orders -Id "MyId"
$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()
Add-GoogleAdsManager -Connection $GoogleAdsManager -Table Orders -Columns @("Id", "Name") -Values @("MyId", "MyName")
$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()
Remove-GoogleAdsManager -Connection $GoogleAdsManager -Table "Orders" -Id "MyId"
$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()
CodeProject
Download a free trial of the DoubleClick (DFP) Data Provider to get started:
Download NowLearn more:
👁 DoubleClick For Publishers IconAn easy-to-use database-like interface for .NET applications access to live DoubleClick For Publishers data (Companies, Contacts, Placements, Users, and more).