Get-TFSProjects.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Author: Miodrag Milic <miodrag.milic@gmail.com>
# Last Change: 26-Apr-2016.

<#
.SYNOPSIS
    Get the list of team projects from the TFS server
#>

function Get-TFSProjects{
    [CmdletBinding()]
    param(
        #Maxium number of team projects to return, by default 100
        [int] $Top=100,
        #Number of team projects to skip, by default 0
        [int] $Skip=0
    )
    check_credential

    $q_top  = '$top=' + $Top + '&'
    $q_skip = '$skip=' + $Skip + '&'
    $query_args = $q_top + $q_skip
    $uri = "$collection_uri/_apis/projects?$($query_args)api-version=" + $global:tfs.api_version
    Write-Verbose "URI: $uri"

    $params = @{ Uri = $uri; Method = 'Get'}
    $r = invoke_rest $params

    $list = @()
    foreach ($r in $r.value) {
        $b = [pscustomobject]@{
            Raw         = $r
            Name        = $r.name
            Description = $r.description
            Revision    = $r.revision
            Id          = $r.id
        }
        $b.PSObject.TypeNames.Insert(0,'TFS.Project')
        $list += $b
    }

    $list
}