forked from StartAutomating/PSDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-ADOTeam.ps1
230 lines (205 loc) · 9.08 KB
/
Get-ADOTeam.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
function Get-ADOTeam
{
<#
.Synopsis
Gets Azure DevOps Teams
.Description
Gets teams from Azure DevOps or TFS
.Link
Get-ADOProject
.Example
Get-ADOTeam -Organization StartAutomating
#>
[CmdletBinding(DefaultParameterSetName='teams')]
[OutputType('PSDevOps.Team','PSDevOps.TeamMember')]
param(
# The Organization.
[Parameter(Mandatory,ValueFromPipelineByPropertyName)]
[Alias('Org')]
[string]
$Organization,
# The project name or identifier
[Parameter(Mandatory,ParameterSetName='projects/{Project}/teams',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='projects/{Project}/teams/{teamId}',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='projects/{Project}/teams/{teamId}/members',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings/teamfieldvalues',
ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings/iterations',
ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/boards',
ValueFromPipelineByPropertyName)]
[Parameter(ParameterSetName='graph/descriptors/{teamId}')]
[string]
$Project,
# If set, will return teams in which the current user is a member.
[Parameter(ParameterSetName='teams',ValueFromPipelineByPropertyName)]
[Parameter(ParameterSetName='projects/{Project}/teams',ValueFromPipelineByPropertyName)]
[Alias('My')]
[switch]
$Mine,
# The Team Identifier
[Parameter(Mandatory,ParameterSetName='projects/{Project}/teams/{teamId}',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='projects/{Project}/teams/{teamId}/members',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings',ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings/teamfieldvalues',
ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings/iterations',
ValueFromPipelineByPropertyName)]
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/boards',
ValueFromPipelineByPropertyName)]
[Parameter(ParameterSetName='graph/descriptors/{teamId}')]
[string]
$TeamID,
# If set, will return members of a team.
[Parameter(Mandatory,ParameterSetName='projects/{Project}/teams/{teamId}/members')]
[Parameter(Mandatory,ParameterSetName='graph/Memberships/{SecurityDescriptor}')]
[Alias('Members','Membership')]
[switch]
$Member,
# The Security Descriptor.
[Parameter(Mandatory,ParameterSetName='graph/Memberships/{SecurityDescriptor}',ValueFromPipelineByPropertyName)]
[Alias('SD','UserDescriptor','TeamDescriptor', 'SubjectDescriptor')]
[string]
$SecurityDescriptor,
# If set, will return the team identity.
[Parameter(Mandatory,ParameterSetName='graph/descriptors/{teamId}')]
[switch]
$Identity,
# If set, will return the team settings.
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings')]
[Alias('Settings')]
[switch]
$Setting,
# If set, will return the team field values.
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings/teamfieldvalues')]
[Alias('FieldValues')]
[switch]
$FieldValue,
# If set, will return iterations for the team.
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/teamsettings/iterations')]
[Alias('Iterations')]
[switch]
$Iteration,
# If set, will list team workboards.
[Parameter(Mandatory,ParameterSetName='/{Project}/{teamId}/_apis/work/boards')]
[Alias('Boards')]
[switch]
$Board,
# If set, will list the security groups.
[Parameter(Mandatory,ParameterSetName='graph/groups')]
[switch]
$SecurityGroup,
# The server. By default https://dev.azure.com/.
# To use against TFS, provide the tfs server URL (e.g. http://tfsserver:8080/tfs).
[Parameter(ValueFromPipelineByPropertyName)]
[uri]
$Server = "https://dev.azure.com/",
# The api version. By default, 5.1-preview.
# If targeting TFS, this will need to change to match your server version.
# See: https://docs.microsoft.com/en-us/azure/devops/integrate/concepts/rest-api-versioning?view=azure-devops
[string]
$ApiVersion = "5.1-preview"
)
dynamicParam { . $GetInvokeParameters -DynamicParameter }
begin {
#region Copy Invoke-ADORestAPI parameters
$invokeParams = . $getInvokeParameters $PSBoundParameters
#endregion Copy Invoke-ADORestAPI parameters
}
process {
$psParameterSet = $psCmdlet.ParameterSetName
$in = $_
if ($in.Project -and $psParameterSet -notlike '*Project*') {
$psParameterSet = 'projects/{Project}/teams'
$project = $psBoundParameters['Project'] = $in.Project
}
if ($in.TeamID -and $psParameterSet -notlike '*TeamID*') {
$psParameterSet = 'projects/{Project}/teams/{teamId}'
}
if ($in.TeamID -and -not $TeamID) {
$TeamID = $in.TeamID
}
if ($in -and $psParameterSet -eq 'teams' -and -not $SecurityDescriptor) {
$lookingForSD = @('SecurityDescriptor') +
$MyInvocation.MyCommand.Parameters['SecurityDescriptor'].Aliases
foreach ($look in $lookingForSD) {
if ($in.$look) {
$SecurityDescriptor = $in.$look
$psParameterSet = $MyInvocation.MyCommand.Parameters['SecurityDescriptor'].Attributes |
Where-Object {$_.ParameterSetName } |
Select-Object -ExpandProperty ParameterSetName -First 1
break
}
}
}
if ($Identity) {
$psParameterSet = $($MyInvocation.MyCommand.Parameters['Identity'].Attributes.ParameterSetName)
}
if ($psParameterSet -like 'graph*') {
$server = 'https://vssps.dev.azure.com/'
}
$uri = # The URI is comprised of:
@(
"$server".TrimEnd('/') # the Server (minus any trailing slashes),
$Organization # the Organization,
if ($psParameterSet.IndexOf('_apis', [Stringcomparison]::OrdinalIgnoreCase) -eq -1) {
'_apis' # the API Root ('_apis'),
}
(. $ReplaceRouteParameter $psParameterSet)
# and any parameterized URLs in this parameter set.
) -as [string[]] -ne '' -join '/'
$uri += '?' # The URI has a query string containing:
$uri += @(
if ($Server -notlike 'https://*.azure.com/' -and
-not $PSBoundParameters.ApiVersion) {
$ApiVersion = '2.0'
}
if ($ApiVersion) { # the api-version
"api-version=$apiVersion"
}
if ($psParameterSet -like '*memberships*') {
if ($Member) {
"direction=Down"
} else {
"direction=Up"
}
}
if ($Mine) {
'$mine=true'
}
) -join '&'
# We want to decorate our return value. Handily enough, both URIs contain a distinct name in the last URL segment.
$typename = @($psParameterSet -split '/' -notlike '{*}')[-1].TrimEnd('s') -replace 'Member', 'TeamMember' # We just need to drop the 's'
$typeNames = @(
"$organization.$typename"
if ($Project) { "$organization.$Project.$typename" }
"PSDevOps.$typename"
)
$invokeParams.Uri = $uri
$invokeParams.PSTypeName = $typeNames
$invokeParams.Property = @{Organization=$Organization;Server=$Server}
if ($Project) { $invokeParams.Property.Project = $Project }
if ($Identity) {
$null = $invokeParams.Property.Remove('Server')
$null = $invokeParams.Property.Remove('Project')
$invokeParams.Property.TeamName =
if ($name) { $name }
elseif ($in.Name)
{ $in.name }
#$invokeParams.Property.TeamID = $TeamID
$invokeParams.PSTypeName = @(
"$Organization.TeamDescriptor"
"$Organization.descriptor"
if ($Project) {
"$Organization.$Project.TeamDescriptor"
"$Organization.$Project.descriptor"
}
'PSDevOps.TeamDescriptor'
'PSDevOps.descriptor'
)
}
Invoke-ADORestAPI @invokeParams
$teamId = $project = '' # Clear values that might not pipe correctly in subsequent runs.
}
}