El TecnoBaúl de Kiquenet

Kiquenet boring stories

Archive for the ‘TFS’ Category

Members, Contributor, Groups, Identities in TFS

Posted by kiquenet en 5 enero 2015

Get members of TFS Group

private List<Identity> ListContributors()
{
    const string projectName = "<<TFS PROJECT NAME>>";
    const string groupName = "Contributors";
    const string projectUri = "<<TFS PROJECT COLLECTION OR URL TFS SERVER>>";

    TfsTeamProjectCollection projectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(projectUri));
    ICommonStructureService css = (ICommonStructureService) projectCollection.GetService(typeof(ICommonStructureService));
    IGroupSecurityService gss = projectCollection.GetService<IGroupSecurityService>();

    // get the tfs project
    var projectList = css.ListAllProjects();
    var project = projectList.FirstOrDefault(o => o.Name.Contains(projectName));

    // project doesn’t exist
    if (project == null) return null;

    // get the tfs group
    var groupList = gss.ListApplicationGroups(project.Uri);
    var group = groupList.FirstOrDefault(o => o.DisplayName.Contains(groupName));  // you can also use DisplayName or AccountName. AccountName is empty for me.

    // group doesn’t exist
    if (group == null) return null;

    Identity sids = gss.ReadIdentity(SearchFactor.Sid, group.Sid, QueryMembership.Expanded);

    // there are no users
    if (sids.Members.Length == 0) return null;

    // convert to a list
    List<Identity> contributors = gss.ReadIdentities(SearchFactor.Sid, sids.Members, QueryMembership.Expanded).ToList();

    return contributors;
}

Add SID to a Readers group

# load the required dll
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")

function get-tfs
{
    param(
    [string] $serverName = $(throw ‘serverName is required’)
    )

    $propertiesToAdd = (
        (‘VCS’, ‘Microsoft.TeamFoundation.VersionControl.Client’, ‘Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer’),
        (‘WIT’, ‘Microsoft.TeamFoundation.WorkItemTracking.Client’, ‘Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore’),
        (‘CSS’, ‘Microsoft.TeamFoundation’, ‘Microsoft.TeamFoundation.Server.ICommonStructureService’),
        (‘GSS’, ‘Microsoft.TeamFoundation’, ‘Microsoft.TeamFoundation.Server.IGroupSecurityService’)
    )

    [psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
    foreach ($entry in $propertiesToAdd) {
        $scriptBlock = ‘
            [System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
            $this.GetService([{1}])
        ‘ -f $entry[1],$entry[2]
        $tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
    }
    return $tfs
}
#set the TFS server url
[psobject] $tfs = get-tfs -serverName
http://YourTfsServer:8080/tfs/YourColleciton

$items = $tfs.vcs.GetAllTeamProjects( ‘True’ )
    $items | foreach-object -process {
    $proj = $_
    $readers = $tfs.GSS.ListApplicationGroups($proj.Name) | ?{$_.DisplayName -eq ‘Readers’ }

    $tfs.GSS.AddMemberToApplicationGroup($readers.Sid, ‘TheSidToTheGroupYouWantToAdd’)
}

var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://vsalm:8080/tfs/FabrikamFiberCollection"));

            var ims = tpc.GetService<IIdentityManagementService>();

            var tfsGroupIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
                                                    "[FabrikamFiber]\\Fabrikam Fiber Web Team",
                                                    MembershipQuery.None,
                                                    ReadIdentityOptions.IncludeReadFromSource);           

            var userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
                                                    "VSALM\\Barry",
                                                    MembershipQuery.None,
                                                    ReadIdentityOptions.IncludeReadFromSource);

            ims.AddMemberToApplicationGroup(tfsGroupIdentity.Descriptor, userIdentity.Descriptor);

Sources:
http://stackoverflow.com/questions/16792995/get-members-of-tfs-group

http://stackoverflow.com/questions/7961727/how-to-grant-read-only-access-to-all-tfs-team-projects-to-a-group-of-users/7971731#7971731

http://blog.ronischuetz.com/2010/04/tfs-api-list-all-tfs-users.html

http://pauravlokesh.wordpress.com/2013/08/13/recursively-list-groups-users-tfsteamprojectcollection/

http://geekswithblogs.net/TarunArora/archive/2011/09/30/tfs-sdk-get-groups-users-permissions-using-tfs-api-with.aspx

Posted in .NET, PowerShell, Scripts, TFS | Etiquetado: , , | Leave a Comment »

Change Owner Workspaces

Posted by kiquenet en 5 enero 2015

For example, maybe Domain is changed in a company.
We have workspaces with the older domain and older user.

Required change to new domain and new user (NEWDOMAIN\NEWUSER).

TFS 2008: The Team Foundation Server for this workspace does not support changing the owner of a workspace.

Using tf.exe command:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

Workspace Command
http://msdn.microsoft.com/en-us/library/y901w7se(v=vs.100).aspx

Workspaces Command
http://msdn.microsoft.com/en-us/library/54dkh0y3(v=vs.100).aspx

Useful commands:

tf workspaces /collection:http://tfsServer:8080 /owner:* /computer:MYCOMPUTER /FORMAT:DETAILED

tf workspace /name:workspacename;workspaceowner /collection:tpcUrl
tf status /collection:tpcUrl /workspace:workspacename;workspaceowner
tf shelve /recursive name;owner *.* /move

tf workspace /new <name> /template:<oldname>;<olduser>

tf workspace /delete PC123;other-user /server:http://tfs:8080

A deleted workspace cannot be recovered.
Workspace ‘PC123′ on server ‘
http://tfs.8080′ has 0 pending change(s).

Are you sure you want to delete the workspace? (Yes/No)

Real usage:

tf workspace /new "MyTeamProject in MYCOMPUTER with owner NEWUSER;NEWDOMAIN\NEWUSER" /template:"MyTeamProject in MYCOMPUTER with owner OLDUSER;OLDERDOMAIN\OLDERUSER" /collection:http://tfsServer:8080

tf workspace /delete /server:http://tfsServer:8080 "MyTeamProject in MYCOMPUTER with owner OLDUSER;OLDERDOMAIN\OLDERUSER"

tf workspace /server:http://tfsServer:8080 "MyTeamProject in MYCOMPUTER with owner NEWUSER;NEWDOMAIN\NEWUSER"

Useful https://tfsworkspacescleaner.codeplex.com/

Sources:

http://www.colinsalmcorner.com/post/workspaces-updating-the-owner

http://willemduncan.github.io/2014-11-10/RemoveTFSWorkspaces/
https://grumpywookie.wordpress.com/2008/04/02/tfs-workspace-for-another-user/

http://roadtoalm.com/2012/09/03/tfs-source-control-2012workspaces-part-2/
http://roadtoalm.com/2012/08/16/tfs-source-control-2012workspaces-part-1/

http://blogs.msdn.com/b/phkelley/archive/2013/05/28/workspaces.aspx
http://davehope.co.uk/Blog/deleting-the-tfs-workspace-for-a-missing-account-fails-tf50605/

Posted in .NET, TFS | Etiquetado: , | Leave a Comment »

Undo, unlock file (User’s checkout) in TFS

Posted by kiquenet en 6 octubre 2014

    Like Brett Rogers posted in StackOverflow:

    There are at least 2 different ways to do this:

    Command Line

    There is a command-line utility called Tf.exe that comes with Team Explorer. Find the documentation here. It can be accessed by launching a Visual Studio Command Prompt window.

  • Open up Visual Studio command prompt (Start -> Programs -> Microsoft Visual Studio 200X -> Visual Studio Tools -> Visual Studio 200X Command Prompt)
  • Run the following command: tf.exe

tf Command
http://msdn.microsoft.com/en-us/library/cc31bk2e.aspx

Deleting the workspace

tf workspace /delete WorkspaceName;User
             /server:http://server:8080/tfs/MyTeamCollection 

tf lock /lock:none /workspace:WorkspaceName;USERNAME /recursive $/

To get the list of workspaces for a user, just run the following command from the same prompt:

tf workspaces /owner:username

Real sample:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tf undo /workspace:TeamAdministration;mydomain\myuser $/Administration/WebUI/App_Data/Web.sitemap /recursive

No pending changes were found for $/Administration/WebUI/App_Data/Web.sitemap.

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tf lock /lock:none /workspace:TeamAdministration;mydomain\myuser $/Administration/WebUI/App_Data/Web.sitemap /recursive

TF10152: The item $/Administration/WebUI/App_Data/Web.sitemapmust remain locked because its file type prevents multiple check-outs.

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tf workspace /delete TeamAdministration;mydomain\myuser

A deleted workspace cannot be recovered.

Workspace ‘TeamAdministration;mydomain\myuser’ on server ‘http://myteamserver:8080/ has 0 pending change(s).

Are you sure you want to delete the workspace? (Yes/No) Y

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>tf undo /workspace:TeamAdministration;mydomain\myuser $/Administration/WebUI/App_Data/Web.sitemap /recursive

TF14061: The workspace TeamAdministration;mydomain\myuser does not exist.

GUI

The second is via the GUI, but does not come standard – you have to install the TFS Power Tools. See here for details on how to use this method.

Keep in mind that with either method you will need the appropriate rights. The permissions are called "Undo other users’ changes" and "Unlock other users’ changes". These permissions can be viewed by:

  1. Right-clicking the desired project, folder, or file in Source Control Explorer
  2. Select Properties
  3. Select the Security tab
  4. Select the appropriate user or group in the Users and Groups section at the top
  5. View the "Permissions for [user/group]:" section at the bottom


Another good option, use the free TFS Sidekick application

Sources:

http://stackoverflow.com/questions/1690520/how-to-undo-another-user-s-checkout-in-tfs

http://stackoverflow.com/questions/268865/what-do-you-do-if-the-file-in-tfs-is-locked-by-someone-else

http://stackoverflow.com/questions/14777535/tfs-file-must-remain-locked

http://xavierdilipkumar.com/post/2013/01/24/TF10152-The-item-$-must-remain-locked-because-its-file-type-prevents-multiple-check-outs.aspx

Posted in Comandos, Soporte, TFS | Etiquetado: , , , , | Leave a Comment »

Using different credentials to connect to Team Foundation Server

Posted by kiquenet en 27 agosto 2014

TFS Cache
<system drive>\Users\<your profile>\AppData\Microsoft\Team Foundation

You can try clearing the cache manually here: C:\Users[USERNAME]\AppData\Local\Microsoft\Team Foundation\5.0\Cache

Control Panel->User Accounts –> Manage your credentials (CredentialManager)

You can also use the command line to open the credential manager.

control /name Microsoft.CredentialManager

This will open the credential manager.

Recently, I had to authenticate to Team Foundation Server using an account with greater permissions to perform some administrative tasks.  As you may know, this requires entering alternate credentials when you add the server to the list of TFS servers, or when you need to connect to the server.  Once you’ve connected once, you aren’t prompted again as the credentials are cached locally.

In the past, to remedy this, you could simply delete the local TFS cache, which is located in the following directory (Windows Vista and onwards):

<system drive>\Users\<your profile>\AppData\Microsoft\Team Foundation

image

However, in more recent versions this has changed somewhat, and the user’s credentials are no longer linked to the local TFS cache or configuration.

Where are the Credentials?

Good question.  After some digging about, it seems that the credentials are now stored in the user’s Credential Manager store within Windows.  If you aren’t familiar with this, it was introduced on the more recent versions of Windows, and it lives via the Control Panel, under the following path: Control Panel->User Accounts

image

Inside this location, you can view all the locally cached credentials, including Windows Credentials:

image

Note: that it appears that for TFS credentials used by Team Explorer and other applications, the credentials are the ones under “Generic Credentials” not under “Windows Credentials” (in case you have TFS entries in both).

Making Changes

To modify or remove the credentials you use to connect to TFS, simply expand the appropriate entry and click on “Edit”, or to delete the local credentials, click on “Remove”.  If you opt to remove the credentials, you’ll be prompted to enter new credentials next time you connect to the specified TFS server.

image

So that was a little out of the way. When I tested this, I made sure that I’d disconnected from TFS before changing/removing the credential configuration.

It would be nice if Team Explorer linked to the Credentials Manager so we didn’t have to go digging to work this out, wouldn’t it?

TFS credentials

When you connect TFS from Visual Studio you will be asked to give user credential to connect. If you checked the option Remember my credentials while connecting TFS, you won’t be asked credentials again to connect TFS. In that case, if you wanted to change different credentials to connect TFS. you need to follow below solution to force Visual Studio to ask new credentials to connect TFS.

Revert TFS credentials in Visual Studio

Force to change TFS credentials in Visual Studio

      You need to remove TFS credentials from Windows Vault to clear and force to ask new TFS credentials in Visual Studio
      1. Go to Control Panel (Start -> Control Panel).
      2. Click User Accounts ( or User Accounts and Family Safety->User Accounts in Windows 7 Machine)
      3. Click Credential Manager (or Manage your credentials)

Remove TFS user credentials in Visual Studio

     4. In Credential Manager page, you can see the two type of credentials
           i. Windows Credentials
           ii. Generic Credentials

     5. Click on two credential’s modify link,  click the link Remove from vault to remove stored TFS credentials.

Now, When you login into Visual Studio you will be asked to give credentials to connect TFS.

Note:
Don’t forgot to uncheck the option Remember my credentials to force to ask credentials for every TFS connections.

References:
http://sanderstechnology.com/2013/using-different-credentials-to-connect-to-team-foundation-server/11865/#.U-iskPl_vij
http://www.morgantechspace.com/2013/09/how-to-change-user-credentials-for-tfs.html

Posted in Seguridad, TFS | Etiquetado: , , | Leave a Comment »

How To: Getting files from Team Foundation Server from the Command Line

Posted by kiquenet en 25 abril 2012

Sometimes it pays to automate things in a batch file so you don’t have to go through the hassle of launching Visual Studio to manually do your tasks.

TFS has a built in command line utility called tf.   If you use the tf get utility, you can get all of your latest source control files from tfs.

1) Launch the command prompt from: Start –> All Programs –> Microsoft Visual Studio 2008 –> Visual Studio Tools –> Visual Studio 2008 Command Prompt

2) type in:
tf get c:\<mylocaldirectory>  /recursive

    and hit enter

http://www.c-sharpcorner.com/Blogs/1219/how-to-getting-files-from-team-foundation-server-from-the-c.aspx

Posted in Scripts, TFS | Leave a Comment »

tf Command-Line Utility Tool in Team Foundation Server

Posted by kiquenet en 3 febrero 2011

Use the tf command line in scripting

Example for get:
cd C:\TFS\Arquitectura
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe get $/Arquitectura/Main /recursive

Example for checkout:
cd C:\TFS\Arquitectura
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe checkout $/Arquitectura/Main /recursive

Example for checkin:
cd C:\TFS\Arquitectura
%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe checkin $/Arquitectura/Main /recursive

%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\TF.exe" get $/Project /recursive for VS 2010 on Win x64.

Referencia de tf.exe

Tf Command-Line Utility Commands
http://msdn.microsoft.com/en-us/library/z51z7zy0(v=VS.90).aspx

Ruta del comando:

%ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\TF.exe

tf Command line utility provide many useful operations that we can perform with Team Foundation Server.

tf add – adds news folder and file from file system to TFS Source Control. Need to do check-in before these file can be visible.
tf add itemspec [/lock:none|checkin|checkout] [/type:filetype] [/noprompt] [/recursive]

tf branch – copies an item/s from one location to another inside TFS Source Control. Need to do check-in before these file can be visible.
tf branch olditem newitem [/version:versionspec] [/noget] [/lock] [/noprompt]

tf branches – displays the history of a branch which can be a file or a folder.
tf branches [/server:servername] itemspec [/version]

tf changeset – displays info about changesets such as comments, notes and etc…
tf changeset [/comment:comment|@commentfile] [/server:servername] [/notes:(“NoteFieldName”=”NoteFieldValue”|@notefile)] [/noprompt] [changesetnumber | /latest]

tf checkin – checks in pending changes to the TFS Source Control.
tf checkin [/author:author name] [/comment:("comment"|@comment file)] [/noprompt] [/notes:(“Note Name”=”note text”|@notefile)] [/override:reasonfile|@reason] [/recursive] [/saved] [/validate] [filespec]

tf checkout – checks out local files for edit.
tf checkout [/lock:(none|checkin|checkout)] [/recursive] [/type:encoding] itemspec

tf configure – updates Source Control Settings with modified Check-out settings; Check-in policies; Check-in notes
tf configure [path of team project] /server:servername

tf delete – removes files and folders from TFS
tf delete [/lock:(none|checkin|checkout)] [/recursive] itemspec

tf diff – displays differences between two files or a shelveset
tf diff[erence] itemspec [/version:versionspec] [/type:filetype] [/format:format [/ignorespace] [/ignoreeol] [/ignorecase] [/recursive] [/options]
tf diff[erence] itemspec itemspec2 [/type:filetype] [/format: format] [/ignorespace] [/ignoreeol] [/ignorecase] [/recursive] [/options]
tf diff[erence] [/shelveset:shelvesetname[;shelvesetowner]] shelveset_itemspec [/server: servername] [/type:filetype] [/format: format] [/ignorespace] [/ignoreeol] [/ignorecase] [/recursive] [/options]
tf diff[erence] /configure

tf dir – presents the contents of the TFS Source Control server
tf dir [/server:servername] itemspec [/version:versionspec] [/recursive] [/folders] [/deleted]

tf get – gets a read-only copy of a file from the TFS to the workspace and creates folders with the file on the disk.
tf get itemspec [/version:versionspec] [/all] [/overwrite] [/force] [/preview] [/recursive] [/noprompt]

tf help – shows help topics about TFS command.
tf help commandname

tf history – shows history of revisions for file/s and folders.
tf history [/server:servername] itemspec [/version:versionspec] [/stopafter:number] [/recursive] [/user:username] [/format:(brief|detailed)] [/slotmode] [/noprompt]

tf label – creates or removes a label from a version of a file or folder
tf label [/server:servername] labelname[@scope] [/owner:ownername] itemspec [/version:versionspec] [/comment:("comment"|@commentfile)] [/child:(replace|merge)] [/recursive]
tf label [/server:servername] /delete labelname[@scope] [/owner:ownername] itemspec [/version:versionspec] [/recursive]

tf labels – shows labels in the TFS
tf labels [/owner:ownername] [/format:(brief|detailed)] [/server:servername] [labelname]

tf lock – locks or unlocks a file or folder
tf lock itemspec /lock:(none|checkout|checkin) [/workspace:workspacename] [/server:servername] [/recursive]

tf merge – applies changes from one branch into another
tf merge [/recursive] [/force] [/candidate] [/discard] [/version:versionspec] [/lock:none|checkin|checkout] [/preview] [/baseless] [/nosummary] source destination

tf merges – shows detailed information about past merges between branches
tf merges [/server:servername] destination [/recursive]

tf properties – presents info about items under TFS Source Control
tf properties [/server:servername] [/recursive] itemspec [/version:versionspec] [/workspace]

tf rename – renames files or folder paths. Also used to move files or folders.
tf rename [/lock:(none|checkout|checkin)] olditem newitem

tf resolve – resolves conflicts between changed items
tf resolve [itemspec] [/auto:(AcceptMerge|AcceptTheirs|AcceptYours|OverwriteLocal|DeleteConflict|AcceptYoursRenameTheirs)] [/preview] [(/overridetype:overridetype | /converttotype:converttype)] [/recursive] [/newname:path]

tf shelve – stores or deletes pending changes with check-in notes, a comment, and work items.
tf shelve [/replace] [/comment:(@commentfile|"comment")] [shelvesetname[;owner] [/validate]
tf shelve [/move] [/replace] [/comment:(@commentfile|"comment")] [/recursive] shelvesetname[;owner] filespec [/validate]
tf shelve /delete [/server:servername] shelvesetname[;owner] [/validate]

tf shelvsets – shows info about a set of shelved changes inside TFS Source Control
tf shelvesets [/owner:ownername] [/format:(brief|detailed)] [/server:servername] shelvesetname

tf status – shows info about pending changes to items
tf status itemspec [/server:servername] ([/workspace:workspacename[;workspaceowner]] | [/shelveset:shelvesetname[;shelvesetowner]]) [/format:(brief|detailed)] [/recursive] [/user:(*|username)]

tf undelete – restores deleted items
tf undelete [/noget] [/lock:(none|checkin|checkout)] [/newname:name] [/recursive] itemspec[;deletionID]

tf undo – removes pending changes from a TFS workspace
tf undo [/workspace:workspacename[;workspaceowner]] [/server:servername] [/recursive] itemspec [/noprompt]

tf unlabel – removes an item from an existing label
tf unlabel [/server:servername] [/recursive] labelname itemspec

tf unshelve – restores shelved file revisions, check-in notes, comments, and work items.
tf unshelve [/move] [shelvesetname[;username]] itemspec [/recursive] [/noprompt]

tf view – retrieves a specific version of a file to a disk
tf view [/server:servername] [/console] [/recursive] [/shelveset:shelvesetname[;owner]] [/noprompt] itemspec [/version:versionspec]

tf workfold – creates, updates, or displays info about the mappings between your workspace and TFS Source Control
tf workfold localfolder
tf workfold [/workspace: workspacename]
tf workfold [/server:servername] [/workspace: workspacename] serverfolder
tf workfold [/map serverfolder localfolder] [/server:servername] [/workspace: workspacename] (serverfolder|localfolder)
tf workfold /unmap [/server:servername] [/workspace: workspacename] [/recursive] (serverfolder|localfolder)
tf workfold /cloak (Team Foundation source control serverfolder|localfolder) [/workspace: workspacename] [/s:servername]
tf workfold /decloak (serverfolder|localfolder) [/workspace: workspacename] [/s:servername]

tf workspace – creates, modifies and views properties and mappings
tf workspace /new [/noprompt] [/template:workspacename[;workspaceowner]] [/computer:computername] [/comment:(“comment”|@comment file)] [/s:servername] [workspacename[;workspaceowner]]
tf workspace /delete [/server:servername] workspacename[;workspaceowner]
tf workspace [/server:servername] [/comment:comment] [/newname:workspacename] [workspacename[;workspaceowner]]

tf workspaces – displays info about workspaces in the system
tf workspaces [/owner:ownername] [/computer:computername] [/server:servername] [/format:(brief|detailed)] [/updateUserName:oldUserName] [/updateComputerName:oldComputerName] workspacename
tf workspaces /remove:(*|workspace1[,workspace2,...]) /server:(*|server)

Posted in Scripts, TFS | Etiquetado: | Leave a Comment »