Ready to get started?

Download a free trial of the Instagram Data Provider to get started:

 Download Now

Learn more:

Instagram Icon Instagram ADO.NET Provider

A straightforward interface to connect any .NET application with Instagram integration capabilities including Users, Relationships, Media, Tags and more!

Automate Instagram Integration Tasks from PowerShell



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

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

PowerShell Cmdlets or ADO.NET Provider?

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

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

Instagram uses the OAuth 2 authentication standard. You will need to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL by registering an app with Instagram. See the help documentation for a guide.

PowerShell

  1. Install the module:

    Install-Module InstagramCmdlets
  2. Connect:

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

    $tagname = "goldfish" $media = Select-Instagram -Connection $instagram -Table "Media" -Where "TagName = `'$TagName`'" $media

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

    $media = Invoke-Instagram -Connection $instagram -Query 'SELECT * FROM Media WHERE TagName = @TagName' -Params @{'@TagName'='goldfish'}

ADO.NET

  1. Load the provider's assembly:

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

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

    $sql="SELECT Link, LikesCount from Media" $da= New-Object System.Data.CData.Instagram.InstagramDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.link $_.likescount }

Update Instagram Data

PowerShell

Update-Instagram -Connection $Instagram -Columns @('Link','LikesCount') -Values @('MyLink', 'MyLikesCount') -Table Media -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Instagram.InstagramCommand("UPDATE Media SET TagName='goldfish' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Instagram.InstagramParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert Instagram Data

PowerShell

Add-Instagram -Connection $Instagram -Table Media -Columns @("Link", "LikesCount") -Values @("MyLink", "MyLikesCount")

ADO.NET

$cmd = New-Object System.Data.CData.Instagram.InstagramCommand("INSERT INTO Media (TagName) VALUES (@myTagName)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Instagram.InstagramParameter("@myTagName","goldfish"))) $cmd.ExecuteNonQuery()

Delete Instagram Data

PowerShell

Remove-Instagram -Connection $Instagram -Table "Media" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.Instagram.InstagramCommand("DELETE FROM Media WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.Instagram.InstagramParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()