_globals.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
$collection_uri = "{0}/{1}" -f $global:tfs.root_url, $global:tfs.collection
$proj_uri       = "{0}/{1}" -f $collection_uri, $global:tfs.project

function check_credential() {
    [CmdletBinding()]
    param()

    if ($global:tfs.Credential) {
        Write-Verbose "TFS Credential: $($global:tfs.Credential.UserName)"
        return
    }

    Write-Verbose 'No credentials specified, trying Windows Credential Manager'
    $global:tfs.Credential = Get-TFSStoredCredential
}

function invoke_rest($Params) {
    $Params.Credential  = $global:tfs.credential

    try {
        Invoke-RestMethod @Params
    } catch {
        $err = $_
        try { $err = $_ | ConvertFrom-Json } catch { throw $err }
        $err = ($err | fl * | Out-String) -join '`n'
        Write-Error $err
    }
}