I need to update same field to same value for hundreds of workitems in TFS. Is there any way to do it in a batch instead of updating them manually one by one?
Asked
Active
Viewed 1.3k times
2 Answers
42
You can do this in Excel:
- Open the work items in Excel, via:
- right click a query in Team Explorer -> open in Excel
- multi-select some work items in a WIT result pane, then right click -> open in Excel
- load Excel, use Team -> Import to load a predefined query
- open a *.xls file that is already bound to TFS
- Make your bulk edits
- Click the Publish button on the Team ribbon
Full documentation: Managing work items in Excel (overview page; lots & lots of links inside)
You can bulk-edit in the web interface too
Windows command line:
REM make Martin Woodward fix all my bugs
tfpt query /format:id "TeamProject\public\My Work Items" |
tfpt workitem /update @ /fields:"Assigned To=Martin"
Powershell:
# make Bill & Steve happy
$tfs = tfserver -path . -all
$items = $tfs.wit.Query("
SELECT id FROM workitems
WHERE [Created By] IN ('bill gates', 'steve ballmer')") |
% {
$_.Open()
$_.Fields["priority"].value = 1
$_
}
# note: this will be much faster than tfpt since it's only one server call
$tfs.wit.BatchSave($items)

p.campbell
- 98,673
- 67
- 256
- 322

Richard Berg
- 20,629
- 2
- 66
- 86
-
1And powershell? (I know you want to dazzle with your l33t powershell skilz again :-) ) – Martin Woodward Jul 31 '09 at 12:38
-
just curious: Is it possible to attach the same file to multiple tfs workitems... either using web interface or powershell? – balalakshmi Jan 04 '11 at 09:42
-
I want to update test case status that is pass or fail via excel..is it possible to do that? – Darshan Apr 15 '13 at 10:50
-
@RichardBerg can you show an example changing the 'Automated Test Name' and 'Automated Status'? I get an error because the 'Automated Status' needs to go from planned to automated... but automated is not in the list of values. – Paul Jul 11 '14 at 13:47
0
$secpasswd = ConvertTo-SecureString $TfsPasswd -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ($TfsUserName, $secpasswd)
Connect-TfsTeamProjectCollection -Server $TfsServerUrl -Collection $TfsCollection -Credential $mycreds
#Get-TfsTeamProject
Connect-TfsTeamProject -Project $TfsProjectName
$workItems = Get-TfsWorkItem -Filter "[System.WorkItemType] = 'Bug' AND [System.AssignedTo] = '$TfsUserName'"
foreach ($workItem in $workItems)
{
$tpc = $workItem.Store.TeamProjectCollection
$id = $workItem.Id
$store = $tpc.GetService([type]'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore')
$wi = $store.GetWorkItem($id)
$projectName = $wi.Project.Name
foreach($fldName in $Fields.Keys)
{
$wi.Fields[$fldName].Value = $Fields[$fldName]
}
$wi.Save()
}
You can download detail script from how to batch update multiple work items in TFS by PowerShell

frank tan
- 131
- 1
- 4