PowerShell 2.0 实践(十三)管理 TFS 2010(3)

来源:互联网 发布:梦幻西游数据账号货源 编辑:程序博客网 时间:2024/06/06 17:39

本次我们继续深入探讨TFS 2010的对象模型,通过PowerShell简洁的进行表达。

测试脚本下载

本系列所有脚本均在Windows Server 2008 R2 DataCenter (PowerShell 2.0) + PowerGUI Script Editor Free Edition x64中测试通过。

TFS 2010系列使用了TFS 2010 Ultimate x64、TFS 2010 Power Tools April 2010。

转载请注明出处:http://www.cnblogs.com/brooks-dotnet/archive/2010/10/12/1849182.html

1、获取TFS 2010中所有的Team Project Collection:

#添加 TFS 2010客户端对象模型程序集

[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

#注意替换为你本机 TFS 2010URL

$instanceBaseUrl= "http://brookspcnb:8080/tfs/";

$tfsServer= New-Object Microsoft.TeamFoundation.Client.TfsConfigurationServer $instanceBaseUrl;

#调用 ITeamProjectCollectionService

$tpcSvc= $tfsServer.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService]);

foreach($coin $tpcSvc.GetCollections())

{

    Write-Host $co.Name

}

运行结果:

可以看到,和GUI中的一致:

脚本中调用了客户端的ITeamProjectCollectionService服务,其实就是个接口,除此之外,TFS 2010还提供了很多其他的服务:(摘自MSDN

Service

TfsConfigurationServer

(server-level)

TfsTeamProjectCollection

(collection-level)

ITeamFoundationRegistry

IIdentityManagementService

ITeamFoundationJobService

IPropertyService

IEventService

ISecurityService

ILocationService

TswaClientHyperlinkService

ITeamProjectCollectionService

 

IAdministrationService

ICatalogService

 

LabFrameworkService

VersionControlServer

 

WorkItemStore

 

IBuildServer

 

ITestManagementService

 

LabFrameworkService

 

LabAdminService

 

LabService

 

IWorkflowIntegrationService

 

ITestIntegrationService

 

ILinking

 

ICommonStructureService3

 

IServerStatusService

 

IProcessTemplates

 

2、获取一个Team Project Collection中所有的Team Project及其签入日期:

#添加 TFS 2010客户端对象模型程序集

[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

$url= New-Object -TypeName Uri-ArgumentList "http://brookspcnb:8080/tfs/DefaultCollection"

$project= New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection-ArgumentList $url

Get-TfsChildItem-Server $project | Select ServerItem,CheckinDate

运行结果:

GUI结果:

3、获取指定Project Collection的更改集ChangeSet:

#添加 TFS 2010客户端对象模型程序集

[Reflection.Assembly]::Load("Microsoft.TeamFoundation.Client, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

$url= New-Object -TypeName Uri-ArgumentList "http://brookspcnb:8080/tfs/DefaultCollection"

$co= New-Object -TypeName Microsoft.TeamFoundation.Client.TfsTeamProjectCollection-ArgumentList $url

Get-TfsChangeset-Server $co –Latest

运行结果:

小结:

本次测试了基本的命令,如查询Team Project Collection、Team Project、ChangeSet等,可以看到都是要使用TFS 2010对象模型的。下一次我们将使用PowerShell创建Team Project Collection、Team Project等,以及添加更改集、提交挂起的更改等。

原创粉丝点击