Automate Instagram Integration Tasks from PowerShell

Jerod Johnson
Jerod Johnson
Director, Technology Evangelism
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 ADO.NET Provider for Instagram 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 Instagram.

ADO.NET Provider

The ADO.NET Provider provides a SQL interface for Instagram; this tutorial shows how to use the Provider to create, retrieve, update, and delete Instagram data.

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. Obtain the OAuthClientId, OAuthClientSecret, and CallbackURL by registering an app with Instagram. See the help documentation for a guide.

  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


$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


$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


$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()

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

Rapidly create and deploy powerful .NET applications that integrate with Instagram data including Users, Relationships, Media, Tags, and more!