TFS 2013 - Link Work Items via Spreadsheet

后端 未结 1 737
伪装坚强ぢ
伪装坚强ぢ 2020-12-22 08:36

I have an Excel worksheet with hundreds of TFS 2013 Work Item IDs populating both Column A and Column B. For illustrative purposes, let\'s just say I have the following:

相关标签:
1条回答
  • 2020-12-22 09:20

    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"
    
    0 讨论(0)
提交回复
热议问题