I have an unusual situation. Since I demonstrate Visual Studio, TFS, and Lab Management a lot, and I’m a field employee, I have everything running on my laptop. I’ve set up my laptop to run Server 2008 R2 SP1, and TFS is on a VM, as is a domain controller, and some lab environments.
Over the past year, I’ve actually created a new TFS VM, detached the old TFS database, and moved it to the new instance. I’ve also decommissioned an old lab environment and created a new one with nearly the same name. That’s left a few state references in my TFS database. I wanted those old references gone—there are some problems in having services listed that don’t really exist any more.
So, for my build server, I used the TFS API and wrote a console application to find the now-departed build agents and unregister them properly. In my case, I’m attaching to “mycollection” on “myserver”, and deleting agents on build servers on a machine named “stalehost”.
The build server installation will also allow you to replace an existing “stale” agent with the one you’re installing. So this is only in the instance that you have a build server that you didn’t unregister and you’re not replacing. Again, I’m connecting to “mycollection” on “myserver”, to unregister the stale environment “Departed Env”.
Now, both of these are single-purpose monolithic console applications. This isn’t elegant code—it’s just a hack to solve a temporary condition. I just thought it was a simple demonstration of the TFS API.