Find file
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (47 sloc) 4.59 KB
<#Creates a zip file containing the requested pending changes for the given ItemSpec from TFS
Requires 7zip and Visual Studio 2010 or greater to be installed
#Set working directory
cd d:\code\myworkspace
#All pending changes
#Single Branch
C:\PATHTO\Export-TFSPatch.ps1 branches\ga2.8.0 -OutputFile .\
[string]$ItemSpec="*", #See for details
[string]$OutputFile #See default below
$tfexe ="C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" #Should match Visual Studio version used to setup workspace
$7zip ="C:\Program Files\7-Zip\7z.exe"
$StripFromPath = $pwd.Path.ToLower().TrimEnd('\')+'\'
$OutputFile = "{0}TFSPatch_{1}.zip" -f $StripFromPath,(get-date -format 'yyyy-MM-dd_HHmmss') #default file name if not provided
#Get TFS details. See for details
Write-Host "`r`nGetting list of pending changes in current workspace" -ForegroundColor Green
Write-Host "WorkingDirectory: $StripFromPath"
Write-Host "Executing: tf.exe status $ItemSpec /format:detailed /recursive`r`n"
$TFSStatus = @(& $tfexe status $ItemSpec /format:detailed /recursive)
if($LASTEXITCODE -ne 0 -or $TFSStatus[0] -eq 'There are no pending changes.'){
Write-Host ""
Write-Error "Invalid workspace '$StripFromPath' or ItemSpec '$ItemSpec'. May need to update tfexe to point to 11.0 or 12.0"
Write-Host "Result of tf.exe status command:"
Write-Host $TFSStatus
Write-Host ""
exit -1
$LocalItems = $TFSStatus | Select-String 'Local item : \[.*\] (.*)' -AllMatches | %{$_.Matches.Groups[1].Value}
$RelativePaths = $LocalItems | %{$_.ToLower().Replace($StripFromPath,'')}
#Create Zip File. See for options
Write-Host "Creating patch file at: $OutputFile" -ForegroundColor Green
& "$7zip" a -mx3 -tzip "$OutputFile" $RelativePaths | Write-Host
if($LASTEXITCODE -ne 0){
Write-Host ""
throw "Error creating $OutputFile. 7Zip failed with exit code $LASTEXITCODE"
} else {
Write-Host ""
Write-Host "Finished creating patch file at: $OutputFile`r`n" -ForegroundColor Green