Automate Azure DevOps Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Azure DevOps ADO.NET Provider

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



Are you looking for a quick and easy way to access Azure DevOps data from PowerShell? We show how to use the Cmdlets for Azure DevOps and the CData ADO.NET Provider for Azure DevOps to connect to Azure DevOps data and synchronize, automate, download, 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.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the Azure DevOps API, 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.

After obtaining the needed connection properties, accessing Azure DevOps data in PowerShell consists of three basic 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 }