views:

455

answers:

2

Hello

I am new to PowerShell and I am trying to get branches from TFS and merge them using a PowerShell script. Unfortunately I am failing a first hurdle.

I do have Visual Studio 2010 install on my local machine and can access the TFS server (also 2010) fine.

I am running the script from my local machine and have the following lines:

$tfs = get-tfs http://TFSServerName:8080/TFSProject
$branchfolders = $tfs.VCS.GetItems('$/Dev/Branches/', $tfs.RecursionType::OneLevel)

and I receive the following error on the second line 2 above

Exception calling "GetItems" with "2" argument(s): "Unable to connect to the remote server"

I have configured the TFS server to accept incoming connections on port 8080 which works but I am now not to sure how to resolve this error. Is further configuration required?

Thanks for any help given.

A: 

First up, you can do most of what you need with tf.exe, the command line tool you get with the TF Client. tf dir, tf get, tf merge, tf resolve and tf checkin will be of interest to you as well as potentially tf branches. We do merges all the time from the command line because only certain options are available from the command line like tf merge /baseless (occassionally) and /discard when we want to eliminate a changeset as a merge candidate. We do this because we have scripts that run nightly on our maintenance branches that let us know how many changesets have been checked in without being merged to Trunk. Sometimes there is a changeset that should never be merged to Trunk e.g. release notes for a specific patch.

There is also a PowerShell snapin for TFS in the Team Foundation Power Tools but it is not as capable as tf.exe. Still for queries it is great because you get back .NET objects.

WRT to the Manning script, are you passing in the full URL including the TF collection name e.g. http://myserver.acme.com:8080/tfs/myteamproject? Finally this $tfs.RecursionType::OneLevel doesn't seem right. Shouldn't it be [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::OneLevel? Sometimes you can specify just the enum value as a string e.g. 'OneLevel' - if the PowerShell .NET method binder can find the right overload.

Keith Hill
Hey. Thanks for the reply. I am using the full path.I have tried all your suggestions for the RecursionType parameter but still recieve this error:Exception calling "GetItems" with "2" argument(s): "TF31002: Unable to connect to this Team Foundation Server: http://MyServer:8080/tfs/dev.Team Foundation Server Url: http://MyServer:8080/tfs/dev.My main goal here is to do a nightly merge from the Trunk to all the development branches.
w4ymo
Does a `TF.exe dir local_mapped_path` work? TF.Exe should be in the VSInstallDir\Common7\IDE. Or for that matter, can you do operations in the Source Control Explorer in Visual Studio? Just wondering if the problem lies somewhere between your PC and the TF server or if it's a problem with using the TFS version control API. One person claimed they uninstalled McAfee and this problem went away. Could it be a local firewall issue? BTW are you on the RTM version of both the TFS 2010 server and VS 2010?
Keith Hill
Thanks for the reply. TF.exe dir local_mapped_path worked and returned a list of all of folder under my team project. I can access TFS fine through Source control explorer in VS 2010. I am running RTM of VS 2010 Premium and RTM of TFS 2010. It could be a local problem but I wouldnt know what to check as only have the default windows 7 firewall and it allows all outgoing traffic and also VS 2010 works fine with TFS.
w4ymo
Hmm, I was able to execute the script and it works for me:$tfs = get-tfs http://tfs.acme.com:8080/tfs/foocoll$tfs.vcs.GetItems('$/Foo/Trunk/settings.stylecop', 'OneLevel')
Keith Hill
Perhaps you should try debugging this with Fiddler? It will show you the http/soap traffic produced by these commands. http://www.fiddler2.com/fiddler2/
Keith Hill
+1  A: 

Thanks for all the help.

I don't understand why this fixes the problem but when I was using the IIS address to the server I was unable to access it. I believe this is working for others but for some reason not me.

e.g.

$tfs = get-tfs http://TFSServerName:8080/TFSProject

was not working but:

$tfs = get-tfs TFSServerName/TFSProject

does work.

w4ymo