TFS2010: Invoking TFS web services using PowerShell

Grant Holliday’s blog

Senior Service Engineer, Microsoft Visual Studio Team Foundation Service

TFS2010: Invoking TFS web services using PowerShell

  • Comments 4

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.

  • Does this still mean that I still need a cal to run the tfs web service directly. Also, what is the benefit of this method if you can use the tfs sdk api to do the work or the data source

  • @questions - take a look at the licensing whitepaper documents listed on blogs.msdn.com/.../tfs-2010-what-service-packs-and-hotfixes-should-i-install.aspx

    It depends what you want to use the web services for. If it is for the purposes of TFS Administration, you may not need one.

    For things like Version Control and Work Item Tracking, it is likely that you'll need one.

  • When I try to do this on my system, I get the following error:

    Exception calling "QueryActiveRequests" with "2" argument(s): "Value cannot be null.

    Parameter name: second"

    I can't quite figure out what I'm doing wrong. Anyone have any hints?

    Thanks.

  • Andy H. - The workaround for exception is to replace $null with TFS 2012 HostID.

    workaround steps @ www.xavierdilipkumar.com/.../Exception-calling-QueryActiveRequests-with-2-argument(s)-Value-cannot-be-null.aspx

Page 1 of 1 (4 items)