In this blog post, I’m going to show you how to invoke the Visual Studio 2010 Team Foundation Web Services remotely using Windows PowerShell 2.0.

There are some TFS administrative functions that can only be performed remotely using the TFS ASMX web services. Over time, there will be powertools and functionality in the command line tools and TFS Administration Console  that allows you to access these. In the meantime though, we have to create our own scripts and utilities for doing this.

PowerShell 2.0 is installed by default in Windows 7 and Windows Server 2008 R2. It includes a new cmdlet called “New-WebServiceProxy”. Using this cmdlet, we can create an in-memory web service proxy for the TFS web services and use it to invoke some useful web methods.

Viewing currently executing requests

1. Open Powershell 2.0 from the Start menu.

image

2. Create the web service proxy by copying this command and replacing your server name in the URL.  The UseDefaultCredentials is required so that we are authenticated to the web service.

$tfsadmin = New-WebServiceProxy –UseDefaultCredential -URI http://tfsserver:8080/tfs/TeamFoundation/administration/v3.0/AdministrationService.asmx?WSDL

image

3. Invoke the QueryActiveRequests web method, expand the ActiveRequests property for each item returned and then format some of the properties (User, Method, etc) as a table (ft).

$tfsadmin.QueryActiveRequests($null, "False") | %{ $_.ActiveRequests } | ft StartTime,UserName,MethodName,RemoteComputer

image

This is a very simple example which should be enough to get you started. Some of the other Administration web services you might want to explore are:

Where possible, you should use the Microsoft.TeamFoundation object model since that is the officially supported API. An example for modifying the TFS registry is included in this post.