There may be times when you need to unconfigure, or remove a build agent configured as a service TFS 2015 and above and there are a few steps missing from the online documentation.
The steps to configure/unconfigure are located here https://www.visualstudio.com/en-us/docs/build/admin/agents/v1-windows
Open a command prompt in admin mode and navigate to the folder where the build agent is located and the ConfigureAgent.cmd file exists. There is a sub folder called agent and this contains vsoagent.exe, which is used to unconfigure the agent from TFS.
Enter command .\agent\vsoagent.exe /unconfigure
Check the Agent Pools tab in TFS to ensure the build agent is no longer appearing.
REMOVE AGENT WINDOWS SERVICE:
There are times when the VSO Agent will not uninstall correctly and a manually removal is required
Open the Services applet to view the list of build services and the name of the service starts with VSO Agent
Run the following query from the command line to find the service names: SC QUERY state= all | FIND "VSO"
Right click on the Build Service to remove and select Properties
Highlight the Service Name and right click and select Copy
Open a Command Prompt in Admin mode
If the build is running: SC STOP vsoagent.localhost.BuildDude
Delete the service
SC DELETE vsoagent.localhost.BuildDude
Run the query to make sure the service is now gone:
SC QUERY state= all | FIND "VSO"
Note: You need to run the command prompt as an administrator, not just logged in as the administrator, but also with administrative rights. If you get errors above about not having the necessary access rights to stop and/or delete the service, run the command prompt as an administrator. You can do this by searching for the command prompt on your start menu and then right-clicking and selecting "Run as administrator".
GENERATE A LIST OF ALL BUILD SERVICES:
If you need to find the short service name of a service, use the following command to generate a text file containing a list of services and their statuses:
SC QUERY state= all | FIND "VSO" >"C:\Service List.txt"