Automate LinkedIn Integration Tasks from PowerShell
The CData ADO.NET Provider for LinkedIn is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to LinkedIn.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for LinkedIn; this tutorial shows how to use the Provider to create, retrieve, update, and delete LinkedIn data.
Once you have acquired the necessary connection properties, accessing LinkedIn data in PowerShell can be enabled in three steps.
LinkedIn uses the OAuth 2 authentication standard. Obtain the OAuthClientId and OAuthClientSecret by registering an app with LinkedIn. For more information refer to our authentication guide.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for LinkedIn\lib\System.Data.CData.LinkedIn.dll") -
Connect to LinkedIn:
$conn= New-Object System.Data.CData.LinkedIn.LinkedInConnection("OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;CallbackURL=http://localhost:portNumber;CompanyId=XXXXXXX;InitiateOAuth=GETANDREFRESH;") $conn.Open() -
Instantiate the LinkedInDataAdapter, execute an SQL query, and output the results:
$sql="SELECT VisibilityCode, Comment from CompanyStatusUpdates" $da= New-Object System.Data.CData.LinkedIn.LinkedInDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.visibilitycode $_.comment }
Update LinkedIn Data
$cmd = New-Object System.Data.CData.LinkedIn.LinkedInCommand("UPDATE CompanyStatusUpdates SET EntityId='238' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.LinkedIn.LinkedInParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert LinkedIn Data
$cmd = New-Object System.Data.CData.LinkedIn.LinkedInCommand("INSERT INTO CompanyStatusUpdates (EntityId) VALUES (@myEntityId)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.LinkedIn.LinkedInParameter("@myEntityId","238")))
$cmd.ExecuteNonQuery()
Delete LinkedIn Data
$cmd = New-Object System.Data.CData.LinkedIn.LinkedInCommand("DELETE FROM CompanyStatusUpdates WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.LinkedIn.LinkedInParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject