Team/TeamAdmin/Team_TeamAdmin.ps1

Function Add-TfsTeamAdmin
{
    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='Medium')]
    [OutputType('TfsCmdlets.TeamAdmins')]
    Param
    (
        # Specifies the board name(s). Wildcards accepted
        [Parameter(Position=0)]
        [Alias('Name')]
        [Alias('User')]
        [object]
        $Identity,

        [Parameter(ValueFromPipeline=$true)]
        [object]
        $Team,

        [Parameter()]
        [object]
        $Project,

        [Parameter()]
        [object]
        $Collection
    )

    Process
    {
        $t = Get-TfsTeam -Team $Team -Project $Project -Collection $Collection; if ($t.Count -ne 1) {throw "Invalid or non-existent team '$Team'."}; if($t.ProjectName) {$Project = $t.ProjectName}; $tp = Get-TfsTeamProject -Project $Project -Collection $Collection; if (-not $tp -or ($tp.Count -ne 1)) {throw "Invalid or non-existent team project $Project."}; $tpc = $tp.Store.TeamProjectCollection

        $id = Get-TfsIdentity -Identity $Identity -Collection $tpc

        $client = _GetRestClient 'TfsCmdlets.TeamAdminHttpClient' -Collection $tpc

        _Log "Adding $($id.IdentityType) '$($id.DisplayName) ($($id.Properties['Account']))' to team '$($t.Name)'"

        if(-not $PSCmdlet.ShouldProcess($t.Name, "Add administrator '$($id.DisplayName) ($($id.Properties['Account']))'"))
        {
            return
        }

        return $client.AddTeamAdmin($tp.Name, $t.Id, $id.Id)
    }
}
Function Get-TfsTeamAdmin
{
    [CmdletBinding()]
    [OutputType('Microsoft.VisualStudio.Services.Identity.Identity')]
    Param
    (
        # Specifies the board name(s). Wildcards accepted
        [Parameter(Position=0)]
        [SupportsWildcards()]
        [object]
        $Identity = '*',

        [Parameter(ValueFromPipeline=$true)]
        [object]
        $Team,

        [Parameter()]
        [object]
        $Project,

        [Parameter()]
        [object]
        $Collection
    )

    Process
    {
        if($Team -is [Microsoft.TeamFoundation.Core.WebApi.WebApiTeam])
        {
            $Project = $Team.ProjectId
        }

        $t = Get-TfsTeam -Team $Team -Project $Project -Collection $Collection -IncludeMembers

        $tpc = Get-TfsTeamProjectCollection -Collection $Collection; if (-not $tpc -or ($tpc.Count -ne 1)) {throw "Invalid or non-existent team project collection $Collection."}

        _Log "Returning team admins from team '$($t.Name)'"

        foreach($member in $t.Members)
        {
            if(-not $member.IsTeamAdmin)
            {
            continue
            }

            $i = Get-TfsIdentity -Identity $member.Identity.Id -Collection $Collection

            if (($i.DisplayName -like $Identity) -or ($i.Properties['Account'] -like $Identity))
            {
                Write-Output $i | `
                    Add-Member -Name TeamId -MemberType NoteProperty -Value $t.Id -PassThru | `
                    Add-Member -Name ProjectId -MemberType NoteProperty -Value $t.ProjectId -PassThru
            }
        }
    }
}
Function Remove-TfsTeamAdmin
{
    [CmdletBinding(SupportsShouldProcess=$true,ConfirmImpact='High')]
    [OutputType('TfsCmdlets.TeamAdmins')]
    Param
    (
        # Specifies the board name(s). Wildcards accepted
        [Parameter(Position=0,ValueFromPipeline=$true)]
        [Alias('Name')]
        [Alias('User')]
        [object]
        $Identity,

        [Parameter()]
        [object]
        $Team,

        [Parameter()]
        [object]
        $Project,

        [Parameter()]
        [object]
        $Collection
    )

    Process
    {
        if($Identity.TeamId -and $Identity.ProjectId)
        {
            $Project = $Identity.ProjectId 
            $t = Get-TfsTeam -Team $Identity.TeamId -Project $Project -Collection $Collection
            
            $tp = Get-TfsTeamProject -Project $Project -Collection $Collection; if (-not $tp -or ($tp.Count -ne 1)) {throw "Invalid or non-existent team project $Project."}; $tpc = $tp.Store.TeamProjectCollection
        }
        else
        {
            $t = Get-TfsTeam -Team $Team -Project $Project -Collection $Collection; if ($t.Count -ne 1) {throw "Invalid or non-existent team '$Team'."}; if($t.ProjectName) {$Project = $t.ProjectName}; $tp = Get-TfsTeamProject -Project $Project -Collection $Collection; if (-not $tp -or ($tp.Count -ne 1)) {throw "Invalid or non-existent team project $Project."}; $tpc = $tp.Store.TeamProjectCollection
        }

        $id = Get-TfsIdentity -Identity $Identity -Collection $tpc

        $client = _GetRestClient 'TfsCmdlets.TeamAdminHttpClient' -Collection $tpc

        _Log "Removing $($id.IdentityType) '$($id.DisplayName) ($($id.Properties['Account']))' from team '$($t.Name)'"

        if(-not $PSCmdlet.ShouldProcess($t.Name, "Remove administrator '$($id.DisplayName) ($($id.Properties['Account']))'"))
        {
            return
        }

        if(-not ([bool] $client.RemoveTeamAdmin($tp.Name, $t.Id, $id.Id).success))
        {
            throw 'Error removing team administrator'
        }
    }
}