Functions/Project/Get-BambooProject.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
<#
.SYNOPSIS
    Gets all projects or describes a single Bamboo Project.
.DESCRIPTION
    If -ProjectKey is specified it describes only that project.
.PARAMETER ProjectKey
    Optional - Key for the Bamboo Project to be described
.EXAMPLE
    Get-BambooProject
.EXAMPLE
    Get-BambooProject -ProjectKey 'PRJ'
#>

function Get-BambooProject {
    [CmdletBinding()]
    param(
        [Parameter()]
        [ValidatePattern('\w+')]
        [string]$ProjectKey,
        [Parameter()]
        [switch]$JsonResponse
    )

    $ContentType = 'application/xml'
    
    if ($JsonResponse -eq $True){
        $ContentType = 'application/json'
    }

    $resource = 'project'
    if ($ProjectKey) {
        $resource = "project/$ProjectKey"
    }

    $response = Invoke-BambooRestMethod -Resource $resource -ContentType $ContentType 
    
    if (-not $JsonResponse){
        $response = $response | Expand-BambooResource -ResourceName 'project'
    }

    $response | Add_ObjectType -TypeName 'PsBamboo.Project'
}