Using scrum, there’s often tasks that you add to every story. Things like “Unit Tests” and “Code Review”, etc.
Entering these in TFS is a pain, so I wrote a quick powershell script to do it for me. This also contains an example of a function inside of a powershell script. If you’re a c# guy, it’s important to note: No parenthesis when calling the function, and no commas between parameters, use spaces instead.
You call it by calling the script name and passing in as a parameter the story number that you want to add the tasks to.
Enjoy!
# You'll need the powertools for TFS. 2015 version is at https://marketplace.visualstudio.com/items?itemName=TFSPowerToolsTeam.MicrosoftVisualStudioTeamFoundationServer2015Power
#############################################################
#
# Description: Automatically creates standard Tasks
# in TFS for a given story.
#
# Created: 2/7/2017
#
#############################################################
Param(
[string]$storyNumber
)
# Clear Output Pane
#clear
# setup some constants
[string] $tfsServerUrl = http://[YourServer]/tfs/[YourCollection]
[string] $projectName = "[YourProject]";
# Loads Windows PowerShell snap-in and related assemblies if not already loaded
if ( (Get-PSSnapin -Name Microsoft.TeamFoundation.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
}
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Common")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
function AddTask($workItemStore, $taskType, $story, $title, $activity, $hours)
{
$task = New-Object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem -ArgumentList $taskType
$task.Title = $title
$task.AreaId = $story.AreaId
$task.IterationId = $story.IterationId
$task["Activity"] = $activity
$task["Remaining Work"] = $hours
$task.Save()
$linkType = $workItemStore.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]
$link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($linkType.ReverseEnd, $story.ID)
$result = $task.Links.Add($link)
$task.Save()
Write-Host $title " task created."
}
# get the TFS collection
$collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsServerUrl)
# get the workitem store
$workitemStore = $collection.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
# get the team project
$project = $workitemStore.Projects[$projectName]
# get the story
$story = $workItemStore.GetWorkItem($storyNumber)
# get the task task type
[Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType]$taskType = [Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemType]$project.WorkItemTypes["Task"]
# Add the tasks.
Write-Host "Adding boilerplate to Story " $story.Id " - " $story.Title
AddTask $workitemStore $taskType $story "Your Title" "Your Activity" YourHours