2016-07-27 24 views
1

我试图用Powershell自动化一些进程。其中之一,无论何时分支,我们都必须手动在我们的TFS站点上搜索“当前版本”查询来搜索用户故事,因此它在搜索参数中具有正确的发布版本。下面的示例截图。如何使用Powershell编辑TFS(网站)上的查询?

enter image description here

这是我会去TFS访问查询,然后进行编辑。下面是编辑器屏幕,我将用新版本的日期替换那里的日期字段。我想要的是通过PowerShell(作为某种TFS对象,我认为)访问这些字段并更新它们。

enter image description here

我一直在用TFS电动工具为PowerShell的插科打诨,以及一些对象的东西时,我得到的服务器$server = New-Object Microsoft.TeamFoundation.Client.TeamFoundationServer($tfsURI)。但通过谷歌,只是搞乱它,我不知道如何编辑从Powershell查询。谁能帮忙?

回答

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' 

## 
0

TFS电动工具无法实现此功能。您可以使用如this article中提到的.Net客户端库或调用VSTS Rest API来执行此操作:Update a query