Remove old shelvesets

Today a customer asked me how to clean up old shelvesets.The October 2008 release of TFS Power Tool contains Get-TfsShelveset and Remove-TfsShelveset cmdlets. The issue is that if one passes the result of Get-TfsShelveset to Remove-TfsShelveset with pipeline, the owner information is ignored and the Remove-TfsShelveset cmdlet will attempt to look up shelveset created by the current user.

Fortunately, Remove-TfsShelveset recognizes owner in terms of “Remove-TfsShelveset –Shelveset name;domain\alias”. So one workaround is to first obtain a list of shelvesets with Get-TfsShelveset cmdlet, then computer the shelvesetspecs and invoke Remove-TfsShelveset understands. The below script will delete all shelvesets created before 90 days ago.

Get-TfsShelveset -server http://170112m3:8080 -owner * | 
Where-Object -Filter {$_.CreationDate -lt [DateTime]::Now.AddDays(-90)} |
ForEach-Object -Process { Remove-TfsShelveset -server http://170112m3:8080 -Shelveset
($_.Name+";"+$_.OwnerName) }