Accessing TFS from Powershell
I am new to PowerShell and I am trying to get branches from TFS and merge th开发者_JAVA百科em 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.
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.
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.
精彩评论