Skip to content

Instantly share code, notes, and snippets.

@pietergheysens
Created January 13, 2016 11:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pietergheysens/49547c2e2717f4edb2e8 to your computer and use it in GitHub Desktop.
Save pietergheysens/49547c2e2717f4edb2e8 to your computer and use it in GitHub Desktop.
Destroy deleted branches in TFS
Write-Host "*** Find deleted branches in TFS and destroy if not used in last 100 days ***" -ForegroundColor Yellow
Add-PSSnapin Microsoft.TeamFoundation.PowerShell
$tfsServer = Get-TfsServer -name http://<tfsserver>:8080/tfs/<tpccollection>
$destroyList = get-tfschilditem -item <versioncontrolpath> -server $tfsServer -Deleted | Where {$_.DeletionId -ne 0 -and $_.CheckinDate -lt (Get-Date).AddDays(-100)}
$deletedBranchesFound = $destroyList.Count
Write-Verbose "Found $deletedBranchesFound deleted branches for starting the destroy command ..." -Verbose
foreach($item in $destroyList)
{
Write-Verbose $item.ServerItem -Verbose
tf destroy $item.ServerItem /noprompt /startcleanup
Write-Verbose ">> deleted branch destroyed" -Verbose
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment