PowerShell 2.0 实践(十三)管理 TFS 2010(3)
2010-10-12 21:07
393 查看
本次我们继续深入探讨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。
转载请注明出处:/article/5136323.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 2010 的URL
$instanceBaseUrl
=
"http://brookspcnb:8080/tfs/";
$tfsServer
=
New-Object
Microsoft.TeamFoundation.Client.TfsConfigurationServer
$instanceBaseUrl;
# 调用 ITeamProjectCollectionService
$tpcSvc
=
$tfsServer.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService]);
foreach($co
in
$tpcSvc.GetCollections())
{
Write-Host
$co.Name
}
运行结果:
可以看到,和GUI中的一致:
脚本中调用了客户端的ITeamProjectCollectionService服务,其实就是个接口,除此之外,TFS 2010还提供了很多其他的服务:(摘自MSDN)
# 添加 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等,以及添加更改集、提交挂起的更改等。
测试脚本下载
本系列所有脚本均在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。
转载请注明出处:/article/5136323.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 2010 的URL
$instanceBaseUrl
=
"http://brookspcnb:8080/tfs/";
$tfsServer
=
New-Object
Microsoft.TeamFoundation.Client.TfsConfigurationServer
$instanceBaseUrl;
# 调用 ITeamProjectCollectionService
$tpcSvc
=
$tfsServer.GetService([Microsoft.TeamFoundation.Framework.Client.ITeamProjectCollectionService]);
foreach($co
in
$tpcSvc.GetCollections())
{
Write-Host
$co.Name
}
运行结果:
可以看到,和GUI中的一致:
脚本中调用了客户端的ITeamProjectCollectionService服务,其实就是个接口,除此之外,TFS 2010还提供了很多其他的服务:(摘自MSDN)
# 添加 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等,以及添加更改集、提交挂起的更改等。
相关文章推荐
- PowerShell 2.0 实践(十三)管理 TFS 2010(3)
- PowerShell 2.0 实践(十一)管理 TFS 2010 (2)
- PowerShell 2.0实践(十)管理TFS 2010 (1)
- PowerShell 2.0 实践(十一)管理 TFS 2010 (2)
- PowerShell 2.0实践(十)管理TFS 2010 (1)
- PowerShell 2.0 实践(四)管理Windows进程
- PowerShell 2.0 实践(十四)管理 SQL Server 2008 R2(2)
- PowerShell 2.0 实践(五)管理Windows注册表
- PowerShell 2.0 实践(七)管理活动目录(上)
- PowerShell 2.0 实践(九)管理活动目录(下)
- PowerShell 2.0 实践(四)管理Windows进程
- PowerShell 2.0 实践(十二)管理 SQL Server 2008 R2(1)
- PowerShell 2.0 实践(五)管理Windows注册表
- PowerShell 2.0 实践(七)管理活动目录(上)
- PowerShell 2.0 实践(四)管理Windows进程
- PowerShell 2.0 实践(五)管理Windows注册表
- PowerShell 2.0 实践(六)管理Windows日志
- PowerShell 2.0 实践(六)管理Windows日志
- PowerShell 2.0 实践(九)管理活动目录(下)
- PowerShell 2.0 实践(八)管理活动目录(中)