Ready to get started?

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

 Download Now

Learn more:

GitHub Icon GitHub ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with GitHub.

Automate GitHub Integration Tasks from PowerShell



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

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

PowerShell Cmdlets or ADO.NET Provider?

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

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

GitHub uses the OAuth 2 authentication standard. To authenticate using OAuth, you will need to create an app to obtain the OAuthClientId, OAuthClientSecret, and CallbackURL connection properties. See the Getting Started chapter of the CData help documentation for an authentication guide.

PowerShell

  1. Install the module:

    Install-Module GitHubCmdlets
  2. Connect:

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

    $userlogin = "mojombo" $users = Select-GitHub -Connection $github -Table "Users" -Where "UserLogin = `'$UserLogin`'" $users

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

    $users = Invoke-GitHub -Connection $github -Query 'SELECT * FROM Users WHERE UserLogin = @UserLogin' -Params @{'@UserLogin'='mojombo'}

ADO.NET

  1. Load the provider's assembly:

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

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

    $sql="SELECT Name, Email from Users" $da= New-Object System.Data.CData.GitHub.GitHubDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.email }

Update GitHub Data

PowerShell

Update-GitHub -Connection $GitHub -Columns @('Name','Email') -Values @('MyName', 'MyEmail') -Table Users -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GitHub.GitHubCommand("UPDATE Users SET UserLogin='mojombo' WHERE Id = @myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.GitHub.GitHubParameter("@myId","10456255-0015501366"))) $cmd.ExecuteNonQuery()

Insert GitHub Data

PowerShell

Add-GitHub -Connection $GitHub -Table Users -Columns @("Name", "Email") -Values @("MyName", "MyEmail")

ADO.NET

$cmd = New-Object System.Data.CData.GitHub.GitHubCommand("INSERT INTO Users (UserLogin) VALUES (@myUserLogin)", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.GitHub.GitHubParameter("@myUserLogin","mojombo"))) $cmd.ExecuteNonQuery()

Delete GitHub Data

PowerShell

Remove-GitHub -Connection $GitHub -Table "Users" -Id "MyId"

ADO.NET

$cmd = New-Object System.Data.CData.GitHub.GitHubCommand("DELETE FROM Users WHERE Id=@myId", $conn) $cmd.Parameters.Add((New-Object System.Data.CData.GitHub.GitHubParameter("@myId","001d000000YBRseAAH"))) $cmd.ExecuteNonQuery()