Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

Create Azure DevOps User Story using Powershell

Posted on January 20, 2020February 27, 2022

In my previous post I talked about creating Azure DevOps(ADO) Task from ITSM Incident. I am going to talk about another use case today. We will create ADO User Story work item from ITSM Change Management Ticket. As mentioned in my previous post, Engineering team is using ADO to track their activities, where as rest of business uses ITSM system to track all there Change Management process in the organization. We need to create a corresponding ADO User Story from the change request entered by the requester. Note, this is just an example use case, you may have some other reason to implement this automation at your work place.

Before we start, we need to identify all required fields we would like to map to the user story from the change request. For my example, I will capture following fields from the change request ticket to update in the newly created user story. You may have different required fields. Feel free to change it accordingly!

Change NumberITSM Change Request Number
RequesterRequester of the Change
CategoryCategory of Change – Infrastructure, Code etc.
Sub-CategorySub Category – Windows, Linux etc.
PriorityChange Priority
System TypeType of system – Production, Non-Production etc.
Business ValueWhy we are making this change – Maintenance,Enhancement etc.
Start DateStart date and time of the implementation of the change
End DateEnd date and time of the implementation of the change
Short DescriptionShort description of the change
DescriptionDetailed description of the change

Following table shows how I am going to map above mentioned fields with ADO user story fields. Again, decide your own fields based on requirements.

TitleChange Number, Short Description
DescriptionChange Number, Requester, Category, Sub-Category, System Type, Business Value, Start Date, End Date, Description
PriorityNumeric Value corresponding to Change Priority 1,2,3 etc.
TagsCategory,Sub-Category

Before we start, as prerequisite, we need a Personal Access Token(PAT) with correct set of permissions to authenticate and authorize on the ADO API. You may use SSH Key or an alternate method to generate credentials. Please refer my previous post on ADO Task creation process to get the steps to generate PAT. In addition, you need your Organization Name and Project Name where we will be creating this work item ready.

With that, let’s generate the authorization header to make REST API calls to ADO API using following code block.

$pacToken = "abcdesomesamplejunkentriesdontuseititwillnotwork"
$organizationName = "MyTestOrg"
$projectName = "MyTestProject"
$adoHeader = @{Authorization=("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "",$pacToken))))}
$adoUserStoryUri = "https://dev.azure.com/$organizationName/$projectName/_apis/wit/workitems/`$User Story?api-version=5.1"

Now, let’s create the main script block to create ADO User story.This is very much similar to the ADO task creation script block with few changes . I am assuming you already collected all required ITSM change request information to use while updating user story details.

#Data retrieved from Change request
$number = "CHG12345" #Enter your change number here
$requester = "Arindam Hazra" #Enter Requester name, I will share a separate script on how to retrieve these informations from ServiceNow using Powershell
$cat = "Infrastructure"
$subcat = "Windows"
$shortDescription = "Patch Winsdows Server - abc"
$description = "Patch Windows Server - abc. Please use the time window 01/20/2019 20:00 - 01/20/2020 22:00. Make sure to stop services for SQL Server, xyz application before startin."
$businessVal = "Maintenance"
$priority = 2
$systemType = "Production"
$startDate = "2020-01-20 20:00"
$endDate = "2020-01-20 22:00"
#Define ADO vaiables 
$title = "$number : $shortDescription"
$comments = "Change Number : $number <br />"
$comments += "Opened By : $requester <br />"
$comments += "Categoty : $cat <br />"
$comments += "SubCategory : $subcat <br />"
$comments += "System Type : $systemType <br />"
$comments += "Business Value : $businessVal <br />"
$comments += "Change Start Date : $startDate <br />"
$comments += "Cange End Date : $endDate <br />"
$comments += "Description : <br />"
$comments += $description
$comments = $comments.replace('"',"'")
$impact = $priority

#Generate JSON body to make the REST API call

$body="[
  {
    `"op`": `"add`",
    `"path`": `"/fields/System.Title`",
    `"value`": `"$title`"
  },
  {
    `"op`": `"add`",
    `"path`": `"/fields/System.Description`",
    `"value`": `"$comments`"
  },
  {
    `"op`": `"add`",
    `"path`": `"/fields/Microsoft.VSTS.Common.Priority`",
    `"value`": `"$impact`"
  },
  {
    `"op`": `"add`",
    `"path`": `"/fields/System.Tags`",
    `"value`": `"$cat;$subcat`"
  }	  
]"
Invoke-RestMethod -Uri $adoUserStoryUri -ContentType "application/json-patch+json" -Body $body -headers $adoHeader -Method POST

Once the script runs successfully, you will receive response like below :

Now, check in Azure DevOps. You should see a User Story has been created in the Project name you provided :

That’s it! we have created an User story in ADO using Powershell!

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
July 2025
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes