List teams and users

From time to time, it can be handy to use the Team configuration and members in TFS to set permissions in another application.

To extract teams and the members from a collection, I’ve made this function.

Function Get-TFSUsers
{
<#
.Synopsis
Extract members and teams from TFS
.PARAMETER TFSURL
Url to TFS collection
.PARAMETER Projects
Array of TFS projects to itereate through
#>
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
[string] $URL,
[Parameter(Mandatory=$true)]
[string[]]$Projects
)

$TFSUsers =@()
Foreach ($Project in $Projects)
{
#Get Teams in project(s)
$Teams = (Invoke-RestMethod -Uri ($URL + '/_apis/projects/'+$Project +'/teams?api-version=2.2') -Method GET -UseDefaultCredentials ).value

Foreach ($Team in $Teams)
{
#Get Team Members
$Members = (Invoke-RestMethod -Uri ($URL + '/_apis/projects/'+$Project +'/teams/' + $Team.name + '/Members?api-version=2.2') -Method GET -UseDefaultCredentials).value

#Create Custom object for team member
Foreach ($Member in $Members)
{ 
$props = @{
'MemberID'=$Member.id
'UniqueName'=$Member.Uniquename
'TeamName'=$Team.name
'TeamID'=$Team.id
'TeamDescription' = $Team.description
'ProjectName' = $Project
}
$TFSUsers += New-Object -TypeName PSObject -Property $props
}
}
}
return $TFSUsers
}

This wil return an array of user objects, with team and project relationsship.

This can then be used for reporting, or to use to set permissions in other applications.

 

Enjoy

Author: KimC

TFS admin and deployment fellow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s