Cmdlets for LinkedIn

Build 21.0.7930

Establishing a Connection

With the CData Cmdlets users can install a data module, set the connection properties, and start scripting. This section provides examples of using our LinkedIn Cmdlets with native PowerShell cmdlets, like the CSV import and export cmdlets.

Installing and Connecting

If you have PSGet, installing the cmdlets can be accomplished from the PowerShell Gallery with the following command. You can also obtain a setup from the CData site.

Install-Module LinkedInCmdlets

The following line is then added to your profile, loading the cmdlets on the next session:

Import-Module LinkedInCmdlets;

You can then use the Connect-LinkedIn cmdlet to create a connection object that can be passed to other cmdlets:

$conn = Connect-LinkedIn -OAuthClientId 'abc123' -OAuthClientSecret 'def456' -CallbackURL 'http://localhost:33333' -CompanyId 'XXXXXXX'

Connecting to LinkedIn

The LinkedIn CompanyId is a string of numbers, usually 6 to 9 digits long, that is unique to your company. You can find this ID in the URL of the search results page when you click on See All Jobs on your LinkedIn Page. The CompanyId is often required in queries for company data. While this may be set directly in the criteria of a query, the CompanyId may be set globally to avoid issues where the query is not so easily modified.

Authenticate via OAuth Authentication

OAuth requires the authenticating user to interact with LinkedIn using the browser. The cmdlet facilitates this in various ways as described below. You can connect without setting any connection properties for your user credentials.

When you connect, the cmdlet opens the LinkedIn OAuth endpoint in your default browser. Log in and grant permissions to the cmdlet. The cmdlet then completes the OAuth process.

See Using OAuth Authentication for other OAuth authentication flows.

Retrieving Data

The Select-LinkedIn cmdlet provides a native PowerShell interface for retrieving data:

$results = Select-LinkedIn -Connection $conn -Table "CompanyStatusUpdates" -Columns @("VisibilityCode, Comment") -Where "EntityId='238'"
The Invoke-LinkedIn cmdlet provides an SQL interface. This cmdlet can be used to execute an SQL query via the Query parameter.

Piping Cmdlet Output

The cmdlets return row objects to the pipeline one row at a time. The following line exports results to a CSV file:

Select-LinkedIn -Connection $conn -Table CompanyStatusUpdates -Where "EntityId = '238'" | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myCompanyStatusUpdatesData.csv -NoTypeInformation

You will notice that we piped the results from Select-LinkedIn into a Select-Object cmdlet and excluded some properties before piping them into an Export-CSV cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each row object in the result set, and we do not necessarily want that information in our CSV file.

However, this makes it easy to pipe the output of one cmdlet to another. The following is an example of converting a result set to JSON:

PS C:\> $conn  = Connect-LinkedIn -OAuthClientId 'abc123' -OAuthClientSecret 'def456' -CallbackURL 'http://localhost:33333' -CompanyId 'XXXXXXX'
PS C:\> $row = Select-LinkedIn -Connection $conn -Table "CompanyStatusUpdates" -Columns (VisibilityCode, Comment) -Where "EntityId = '238'" | select -first 1
PS C:\> $row | ConvertTo-Json
  "Connection":  {

  "Table":  "CompanyStatusUpdates",
  "Columns":  [

  "VisibilityCode":  "MyVisibilityCode",
  "Comment":  "MyComment"

Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into LinkedIn, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyCompanyStatusUpdatesUpdates.csv | %{
  $record = Select-LinkedIn -Connection $conn -Table CompanyStatusUpdates -Where ("Id = `'"+$_.Id+"`'")
    Update-LinkedIn -Connection $conn -Table CompanyStatusUpdates -Columns @("VisibilityCode","Comment") -Values @($_.VisibilityCode, $_.Comment) -Where "Id  = `'$_.Id`'"
    Add-LinkedIn -Connection $conn -Table CompanyStatusUpdates -Columns @("VisibilityCode","Comment") -Values @($_.VisibilityCode, $_.Comment)

Copyright (c) 2021 CData Software, Inc. - All rights reserved.
Build 21.0.7930