Automate LinkedIn Ads Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

LinkedIn Ads ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with LinkedIn Ads.



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

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

Cmdlets or ADO.NET?

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

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

LinkedIn Ads uses the OAuth authentication standard. OAuth requires the authenticating user to interact with LinkedIn using the browser. See the OAuth section in the Help documentation for a guide.

PowerShell

  1. Install the module:

    Install-Module LinkedInAdsCmdlets
  2. Connect:

    $linkedinads = Connect-LinkedInAds -OAuthClientId "$OAuthClientId" -OAuthClientSecret "$OAuthClientSecret" -CallbackURL "$CallbackURL"
  3. Search for and retrieve data:

    $entityid = "238" $analytics = Select-LinkedInAds -Connection $linkedinads -Table "Analytics" -Where "EntityId = `'$EntityId`'" $analytics

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

    $analytics = Invoke-LinkedInAds -Connection $linkedinads -Query 'SELECT * FROM Analytics WHERE EntityId = @EntityId' -Params @{'@EntityId'='238'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.LinkedInAds.LinkedInAdsConnection("OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the LinkedInAdsDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT VisibilityCode, Comment from Analytics" $da= New-Object System.Data.CData.LinkedInAds.LinkedInAdsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.visibilitycode $_.comment }