forked from WeAreInSpark/AzureDevOpsPowerShellAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-AzDoAllTeams.ps1
More file actions
93 lines (84 loc) · 2.55 KB
/
Copy pathGet-AzDoAllTeams.ps1
File metadata and controls
93 lines (84 loc) · 2.55 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
91
92
93
function Get-AzDoAllTeams {
<#
.SYNOPSIS
This script gets all teams within an organization.
.DESCRIPTION
This script retrieves all teams within an organization using the Azure DevOps REST API.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contoso/'
ExpandIdentity = $true
Mine = $true
}
Get-AzDoAllTeams @params
This example gets all teams within 'contoso' where the requesting user is a member.
.OUTPUTS
PSObject
.NOTES
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection URI. e.g. https://dev.azure.com/contoso.
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[String]
$CollectionUri,
# Whether or not to return detailed identity info
[Parameter(ValueFromPipelineByPropertyName)]
[Switch]
$ExpandIdentity = $false,
# Filter only teams your identity is member of
[Parameter(ValueFromPipelineByPropertyName)]
[Switch]
$Mine = $false,
# Skip number N of results
[Parameter(ValueFromPipelineByPropertyName)]
[Int]
$Skip = 0,
# Show only top N results
[Parameter(ValueFromPipelineByPropertyName)]
[Int]
$Top = 0
)
process {
$result = @()
Write-Verbose "Starting function: Get-AzDoAllTeams"
$queryParams = @()
if ($ExpandIdentity) {
$queryParams += "`$expandIdentity=$ExpandIdentity"
}
if ($Mine) {
$queryParams += "`$mine=$Mine"
}
if ($Skip -gt 0) {
$queryParams += "`$skip=$Skip"
}
if ($Top -gt 0) {
$queryParams += "`$top=$Top"
}
$queryParams = $queryParams -join "&"
$uri = "$CollectionUri/_apis/teams"
$version = "7.1-preview.3"
$params = @{
Uri = $uri
Version = $version
QueryParameters = $queryParams
Method = 'GET'
}
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get all teams in organization")) {
(Invoke-AzDoRestMethod @params).value | 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)"
}
}
}