如何使用PowerShell格式化TFS工作项AssignedTo字段

时间:2013-09-17 07:44:16

标签: powershell tfs tfs2012 tfs-power-tools

我正在使用TFS 2012 Power Tools和PowerShell来显示包含更改集的工作项,这些更改集在过去120天内修改了给定目录下的源文件。在StackOverflow的大量帮助下,我找到了工作项并将其显示如下:

PS> $items = Get-TfsItemHistory $/Somewhere -R -All -Version "D$((Get-Date).AddDays(-120).ToString('d'))~" | select ChangesetId -ExpandProperty WorkItems | Sort-Object -Unique Id
PS> $items | format-table

这看起来相当不错,例如,这是输出的开始:

Id    State    AssignedTo    AreaPath            Title
--    -----    ----------    --------            -----
32604 Closed   Harald Han... Client\Domain\Nav   Change to new address space

但是,如果我尝试仅显示字段的子集,则无法显示AssignedTo字段。这没关系:

PS> $items | format-table AreaPath, State

AreaPath                  State
--------                  -----
KCS-Client\Domain\Nav     Closed

但这不是:

PS > $items | format-table AssignedTo, State

AssignedTo                State
----------                -----
                          Closed

我一定错过了一些微不足道的东西,但(作为PowerShell和TFS PowerTools的相对新手)我看不出它是什么。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

属性“AssignedTo”是在运行时从scriptproperty powershell自定义格式文件中评估的Microsoft.TeamFoundation.PowerTools.PowerShell.format.ps1xml

该值取自:

 $_.Fields[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreField]::AssignedTo].Value

然后我认为(我无法测试它,因为我没有TF服务器源)你需要这样做:

$items | format-table @{n="AssignedTo";e={$_.Fields[[Microsoft.TeamFoundation.WorkItemTracking.Client.CoreField]::AssignedTo].Value}} , State