Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.