Get list files from a changeset using Microsoft.TeamFoundation.Client and Powershell

旧城冷巷雨未停 提交于 2019-12-04 21:24:28
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer) 
$versionControlType = [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer] 
$versionControlServer = $tfs.GetService($versionControlType) 

$latest = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest
$recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full # 'Full'

# If specified, format should be like "Dyyyy-MM-ddThh:mm". 
#.EXAMPLE      C:\Export-TFS-Changes-To-Excel.ps1 -dateFrom D2014-10-20T00:00 -dateTo D2014-10-24T00:00 

$dateFrom = "D2015-03-17T00:00" 
$dateTo = "D2015-05-05T00:00" 

$userName = $null 
$versionFrom = $null 
$versionFrom = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec($dateFrom, "") 
$versionTo = $null 
$versionTo = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec($dateTo, "") 


$path="c:\MyProject\SpecialFolder\*"
$path="$/TeamProject/Main/Portal-branch"
$locationToSearch = $path

$vCSChangeSets = $versionControlServer.QueryHistory($locationToSearch, $latest, 0, $recursionType, $userName, $versionFrom, $versionTo, [int32]::MaxValue, $true ,$false, $false, $true) 
$TargetChangeSetChangeItems = @()  


$TargetChangeSetChangeItems = foreach ($vCSChangeSet in $vCSChangeSets) 
{   
    foreach ($vCSChange in $vCSChangeSet.Changes) 
    { 
        $vCSItem =  $vCSChange.Item 

        # MORE CODE HERE, OMMITTED
    }
}

References:
https://gallery.technet.microsoft.com/scriptcenter/Export-Foundation-Server-b664c8ce

Maybe using VersionControlServer

$tfsServer = "http://server:8080"

Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ReferenceAssemblies\v2.0\Microsoft.TeamFoundation.Client.dll"

#Set up connection to TFS Server and get version control 
$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($tfsServer) 
$versionControlType = [Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer] 
$versionControlServer = $tfs.GetService($versionControlType) 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!