forked from WeAreInSpark/AzureDevOpsPowerShellAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-AzDoProjectTeam.ps1
More file actions
90 lines (84 loc) · 2.75 KB
/
Get-AzDoProjectTeam.ps1
File metadata and controls
90 lines (84 loc) · 2.75 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function Get-AzDoProjectTeam {
<#
.SYNOPSIS
This script gets team details in a given project.
.DESCRIPTION
This script gets teams in a given project.
When used in a pipeline, you can use the pre-defined CollectionUri, ProjectName, and AccessToken (PAT) variables.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contoso/'
ProjectName = 'Project 1'
TeamName = 'testteam'
}
Get-AzDoProjectTeam @params
This example gets the team 'testteam' in 'Project 1'.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contoso/'
ProjectName = 'Project 1'
}
Get-AzDoProjectTeam @params
This example gets all teams in 'Project 1'.
.OUTPUTS
PSObject
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection URI
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,
# Project name of the project
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$ProjectName,
# team name
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$TeamName
)
process {
Write-Verbose "Starting function: Get-AzDoProjectTeam"
$params = @{
uri = "$CollectionUri/_apis/projects/$ProjectName/teams"
version = "7.1-preview.3"
method = 'GET'
}
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get teams from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
try {
$teams = (Invoke-AzDoRestMethod @params).value
} catch {
$PSCmdlet.ThrowTerminatingError((Write-AzDoError -message "Failed to get teams for project '$ProjectName'. Error: $_"))
}
if ($TeamName) {
$teams | Where-Object { $_.name -eq $TeamName } | ForEach-Object {
[PSCustomObject]@{
CollectionURI = $CollectionUri
ProjectName = $ProjectName
TeamName = $_.name
TeamId = $_.id
Description = $_.description
Url = $_.url
IdentityUrl = $_.identityUrl
}
}
} else {
$teams | ForEach-Object {
[PSCustomObject]@{
CollectionURI = $CollectionUri
ProjectName = $ProjectName
TeamName = $_.name
TeamId = $_.id
Description = $_.description
Url = $_.url
IdentityUrl = $_.identityUrl
}
}
}
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)"
}
}
}