TFS 2013 - Link Work Items via Spreadsheet

筅森魡賤 提交于 2019-11-29 18:01:17

If you save the spreadsheet as a .csv file and have two columns with headings Parent and Child then using this excellent blog post as inspiration:

http://www.colinsalmcorner.com/post/bulk-migrate-work-item-comments-links-and-attachments

Try this:

$tpcUrl = "http://myserver:8080/tfs/MyCollection"
$csvFile = ".\map.csv" #format: Parent, Child

[Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Common')
[Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.Client')
[Reflection.Assembly]::LoadWithPartialName('Microsoft.TeamFoundation.WorkItemTracking.Client')

$tpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tpcUrl)
$wis = $tpc.GetService([Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore])

$list = Import-Csv $csvFile

foreach($map in $list) 
{
   $childWIT = $wis.GetWorkItem($map.Child)

   Write-Host "Creating Link from Parent:$($map.Parent) to Child:$($map.Child)" -ForegroundColor Green

   $hierarchyLink = $wis.WorkItemLinkTypes[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreLinkTypeReferenceNames]::Hierarchy]
   $link = new-object Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemLink($hierarchyLink.ReverseEnd, $map.Parent)    
   $childWIT.WorkItemLinks.Add($link)
   try 
   {
      $childWIT.Save();
      Write-Host "Link created" -ForegroundColor DarkGreen
   }
   catch 
   {
      Write-Error "Could not save work item $map.Child"
      Write-Error $_
   }
}

Write-Host
Write-Host "Linking complete"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!