如何使用Powershell在TFS(网站)上编辑查询?

时间:2016-07-27 16:23:56

标签: api powershell tfs tfs-power-tools

我尝试使用Powershell自动化某些流程。其中之一,无论何时我们进行分支,我们都必须手动修改"当前版本"在我们的TFS网站上查询用户故事,因此它在搜索参数中具有正确的发布版本。以下示例截图。

enter image description here

这是我在TFS上访问查询然后编辑它的地方。下面是编辑器屏幕,我将其中的日期字段替换为新版本的日期。我想要的是通过powershell访问这些字段(我认为是某种TFS对象)并更新它们。

enter image description here

我一直在使用TFS Power Tools for Powershell,以及当我获得服务器$server = New-Object Microsoft.TeamFoundation.Client.TeamFoundationServer($tfsURI)时的一些对象内容。但是通过google-fu并且只是弄乱它,我无法弄清楚如何从Powershell编辑查询。有人可以帮忙吗?

2 个答案:

答案 0 :(得分:0)

这不是您问题的直接答案,但下面可能足以让您开始自己解决问题。我想你可能会使用$version_control_server

##
# http://blog.majcica.com/2015/11/15/powershell-tips-and-tricks-retrieving-tfs-collections-and-projects/
#   this will get you a list of tfs projects hosted on a tfs server
##

# Add-Type -AssemblyName "Microsoft.TeamFoundation.Client, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Add-Type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.Client.dll'

$uri = 'http://host:8080/tfs'

$tfsConfigurationServer = [Microsoft.TeamFoundation.Client.TfsConfigurationServerFactory]::GetConfigurationServer($uri)
$tpcService = $tfsConfigurationServer.GetService('Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService')

$sortedCollections = $tpcService.GetCollections() | Sort-Object -Property Name

#

$collection = $sortedCollections[0]

$collectionUri = $uri + '/' + $collection.Name
$tfsTeamProject = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($collectionUri)
$cssService = $tfsTeamProject.GetService('Microsoft.TeamFoundation.Server.ICommonStructureService3')   
$sortedProjects = $cssService.ListProjects() | Sort-Object -Property Name


##
# https://lajak.wordpress.com/2013/01/28/tfs-2012-api-find-all-solutions-in-source-control/
#  this will take your list of projects and get list of solution paths within those projects
##


Add-Type -Path 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Microsoft.TeamFoundation.VersionControl.Client.dll'

$version_control_server = $tfsTeamProject.GetService('Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer')

$solution_items = $version_control_server.getitems(
    '$/*',
    [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest,
    [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full,
    [Microsoft.TeamFoundation.VersionControl.Client.DeletedState]::NonDeleted,
    [Microsoft.TeamFoundation.VersionControl.Client.ItemType]::File
)

$path_array = $solution_items.items | foreach-object { $_.serveritem }

($path_array -join "`r`n") | out-file 'C:\tfs_paths.txt'

##

答案 1 :(得分:0)

TFS Power Tools无法实现此功能。您可以使用this article中提到的.Net客户端库,也可以调用VSTS Rest API执行此操作:Update a query