I use TFS 2008 in a company.
How can I get list of files from a TFS changeset using Microsoft.TeamFoundation.Client
and Powershell
?
My script:
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"
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)
来源:https://stackoverflow.com/questions/30032601/get-list-files-from-a-changeset-using-microsoft-teamfoundation-client-and-powers