Automate Azure DevOps Integration Tasks from PowerShell



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

The CData Cmdlets for Azure DevOps are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Azure DevOps.

PowerShell Cmdlets or ADO.NET Provider?

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

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

You can connect to your Azure DevOps account by providing the Organization and PersonalAccessToken.

Obtaining a Personal Access Token

A PersonalAccessToken is necessary for account authentication.

To generate one, log in to your Azure DevOps Organization account and navigate to Profile -> Personal Access Tokens -> New Token. The generated token will be displayed.

If you wish to authenticate to Azure DevOps using OAuth refer to the online Help documentation for an authentication guide.

PowerShell

  1. Install the module:

    Install-Module AzureDevOpsCmdlets
  2. Connect:

    $azuredevops = Connect-AzureDevOps -AuthScheme "$AuthScheme" -Organization "$Organization" -ProjectId "$ProjectId" -PersonalAccessToken "$PersonalAccessToken"
  3. Search for and retrieve data:

    $reason = "Manual" $builds = Select-AzureDevOps -Connection $azuredevops -Table "Builds" -Where "Reason = `'$Reason`'" $builds

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

    $builds = Invoke-AzureDevOps -Connection $azuredevops -Query 'SELECT * FROM Builds WHERE Reason = @Reason' -Params @{'@Reason'='Manual'}

ADO.NET

  1. Load the provider's assembly:

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

    $conn= New-Object System.Data.CData.AzureDevOps.AzureDevOpsConnection("AuthScheme=Basic;Organization=MyAzureDevOpsOrganization;ProjectId=MyProjectId;PersonalAccessToken=MyPAT;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the AzureDevOpsDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Id, BuildNumber from Builds" $da= New-Object System.Data.CData.AzureDevOps.AzureDevOpsDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.buildnumber }

Ready to get started?

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

 Download Now

Learn more:

Azure DevOps Icon Azure DevOps ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with Azure DevOps.