Working with APIs has become tremendously increased & necessary for getting and managing data. Many of the programming and scripting languages supports API call with its native functionality. After the introduction of Invoke-RestMethod
in PowerShell
it has become more fun to work with APIs as we will have the results in objects than a plain text in the working session. This has become more useful when we automate some tasks with PowerShell.
One such is Azure DevOps API, you can view the official documentation here. The API documentation is vast and it could be hard to construct url for each and every API call. There are client SDKs available which makes easy to work with this vast API. One such simple SDK or a module for PowerShell is psAzD available in PowerShell Gallery. This is a wrapper for Azure DevOps API which exactly replicates the construction of URL as per the documentation.
Let’s explore the working and usage of psAzD module in this post.
Table of Contents
- Installation
- Getting Started
- Cmdlet Naming Convention
- Examples
- Closing
Installation
Install psAzD module from PowerShell Gallery if you are using PowerShell version 5.1 or above. Since it is not open sourced yet, this is the only way to get the module.
# you need elevated permission to download for system scope
PS C:\> Install-Module -Name psAzD -Scope CurrentUser
Getting Started
As of now the only released version is v3.1.0 and there are bunch of cmdlets available in the module which are separated by services and it’s resources. You will need Azure DevOps
personal access token to retrieve the information API. You can view the official documentation here to know how to set up your personal access token.
psAzD provide tab completion for Project Id
, Repository Name
, Team Id
as of now.
- Run help with the module name to view a brief intro about the module.
# if you are using windows system you can run the below cmdlet with -ShowWindow switch to view the help in a nice gui.
PS C:\> Get-Help psAzD
- Most of the cmdlets require you to provide OrganizationName, AzureDevOpsToken and ProjectName. Setting all these as the default parameters helps to work with the module easily. This way you don’t have set these parameter for all the cmdlets you run, these will be set as environment variables in the current process or PowerShell session you run and picked up dynamically for cmdlets for which these are mandatory parameters.
PS C:\> Set-AzDDefaultParameters `
-Organization "Organization Name" `
-PersonalAccessToken "Azure DevOps Personal Access Token" `
-Project "Project Name"
That’s it, you are set. Now lets explore some useful cmdlets and it’s functions.
- Each and every cmdlet has help embedded and linked to official documentation. So when you run
help cmdlet-name -online
for a cmdet you will be diverted to the appropriate online documentation page.
Cmdlet Naming Convention
Each cmdlet is named with prefix AzD which stands for Azure DevOps followed by it’s service and it’s resource.
For instance, the cmdlet to query all projects of your organization is Get-AzDCoreProjects where AzD
stands for Azure DevOps, Core
is the service and Projects
is the resource.
Examples
- Now that the default parameters are set in the current session, lets retrieve information API.
Closing
Provided are few cmdlets that I found more useful, there are other useful cmdlets which helps to get the granular level information from Azure DevOps API. Feel free to explore and raise for any concerns from the contact owner section in PowerShell Gallery.