Question

When using PowerShell to extract information from TFS, I find that I can get at the standard fields but not "Custom" fields. I'm not sure custom is the correct term, but for example if I look at the Process Editor in VS2008 and edit the Work Item type, there are fields such as listed below, with Name, Type and RefName:

Title         String    System.Title
State         String    System.State
Rev           Integer   System.Rev
Changed By    String    System.ChangedBy

I can access these with Get-TfsItemHistory:

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -R 
  | Select -exp WorkItems | Format-Table Title, State, Rev, ChangedBy -Auto

So far so good.

However, there are also some other fields in the WorkItem type, which I'm calling "Custom" or non-System fields, e.g.:

Activated By  String    Microsoft.VSTS.Common.ActivatedBy
Resolved By   String    Microsoft.VSTS.Common.ResolvedBy

And the following command does not retrieve the data, just spaces.

Get-TfsItemHistory "$/path" -Version "D01/12/10~" -R 
  | Select -exp WorkItems | Format-Table ActivatedBy, ResolvedBy -Auto

I've also tried the names in quotes, the fully qualified refname, but no luck. How do you access these "non-System" fields?

Thanks

Boz

UPDATE:

From Keith's answer I can get the fields I need:

Get-TfsItemHistory "$/Hermes/Main" -Version "D01/12/10~" -Recurse `
  | Select ChangeSetId, Comment -exp WorkItems `
  | Select ChangeSetId, Comment, @{n='WI-Id'; e={$_.Id}}, Title -exp Fields `
  | Where {$_.ReferenceName -eq 'Microsoft.VSTS.Common.ResolvedBy'} `
  | Format-Table ChangesetId, Comment, WI-Id, Title, @{n='Resolved By'; e={$_.Value}} -Auto

Notes: Renaming of WorkItem's Id to WI-Id necessary because Id is ambiguous with Field Id. Renaming the Fields Value property gives a column heading name instead of "Value".

Was it helpful?

Solution

There is a Fields collection property in each work item that appears to contain all the work item fields and values. Access it like so:

Get-TfsItemHistory . -r -vers "D12/14/2010~" | 
    Where {$_.WorkItems.count -gt 0} | Select -Expand workitems | 
    Select @{n='WIT-Id';e={$_.Id}},Title -Expand Fields | 
    Where {$_.ReferenceName -eq 'Microsoft.VSTS.Common.ActivatedBy'} | 
    Format-Table Value,WIT-Id,Title -auto
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top