Skip to content

Commit 799e755

Browse files
Get-ADOPermission: Now Supporting Addtional Easy Permissions:
* Analytics * AreaPaths * Dashboards * IterationPaths Slight Internal Refactoring.
1 parent e958934 commit 799e755

File tree

1 file changed

+118
-33
lines changed

1 file changed

+118
-33
lines changed

Get-ADOPermission.ps1

Lines changed: 118 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
Gets Azure DevOps security permissions.
88
.Example
99
Get-ADOPermission -Organization MyOrganization -Project MyProject -PersonalAccessToken $pat
10+
.Example
11+
Get-ADOProject -Organization MyOrganization -Project MyProject | # Get the project
12+
Get-ADOTeam | # get the teams within the project
13+
Get-ADOPermission -Dashboard # get the dashboard permissions of each team within the project.
1014
.Link
1115
https://docs.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20lists/query
1216
.Link
@@ -44,19 +48,38 @@
4448
$SecurityToken,
4549

4650
# The Project ID.
47-
# If this is provided without anything else, will get permissions for the projectID
51+
# If this is provided without anything else, will get permissions for the projectID
4852
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Project')]
53+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Analytics')]
54+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='AreaPath')]
55+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Dashboard')]
4956
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Tagging')]
5057
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='ManageTFVC')]
5158
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildDefinition')]
5259
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildPermission')]
53-
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='RepositoryID')]
60+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='IterationPath')]
61+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='RepositoryID')]
5462
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='ProjectRepository')]
55-
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='ProjectOverview')]
63+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='ProjectOverview')]
5664
[Alias('Project')]
5765
[string]
5866
$ProjectID,
5967

68+
# If provided, will get permissions related to a given teamID. ( see Get-ADOTeam)
69+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Dashboard')]
70+
[string]
71+
$TeamID,
72+
73+
# If provided, will get permissions related to an Area Path. ( see Get-ADOAreaPath )
74+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='AreaPath')]
75+
[string]
76+
$AreaPath,
77+
78+
# If provided, will get permissions related to an Iteration Path. ( see Get-ADOIterationPath )
79+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='IterationPath')]
80+
[string]
81+
$IterationPath,
82+
6083
# If set, will get common permissions related to a project.
6184
# These are:
6285
# * Builds
@@ -77,11 +100,27 @@
77100
[switch]
78101
$Tagging,
79102

103+
# If set, will get permissions for analytics related to the current project.
104+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Analytics')]
105+
[switch]
106+
$Analytics,
107+
80108
# If set, will get permissions for Team Foundation Version Control related to the current project.
81109
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='ManageTFVC')]
82110
[switch]
83111
$ManageTFVC,
84112

113+
# If set, will get permissions for Delivery Plans.
114+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Plan')]
115+
[switch]
116+
$Plan,
117+
118+
# If set, will get dashboard permissions related to the current project.
119+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Dashboard')]
120+
[Alias('Dashboards')]
121+
[switch]
122+
$Dashboard,
123+
85124
# The Build Definition ID
86125
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildDefinition')]
87126
[string]
@@ -90,7 +129,7 @@
90129
# The path to the build.
91130
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='BuildDefinition')]
92131
[string]
93-
$Path ='/',
132+
$BuildPath ='/',
94133

95134
# If set, will get build and release permissions for a given project.
96135
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildPermission')]
@@ -176,92 +215,138 @@
176215
$ProgressPreference = $oldProgressPref
177216
if (-not $ProjectID) { return }
178217
}
179-
switch -Regex ($psCmdlet.ParameterSetName) {
218+
$psBoundParameters["ParameterSet"] ='accesscontrollists/{NamespaceId}'
219+
switch -Regex ($psCmdlet.ParameterSetName) {
180220
Project {
181221
$null = $PSBoundParameters.Remove('ProjectID')
182-
$q.Enqueue(@{
183-
ParameterSet='accesscontrollists/{NamespaceId}'
222+
$q.Enqueue(@{
184223
NamespaceID = '52d39943-cb85-4d7f-8fa8-c6baac873819'
185224
SecurityToken = "`$PROJECT:vstfs:///Classification/TeamProject/$ProjectID"
186225
} + $PSBoundParameters)
226+
227+
}
228+
'AreaPath|IterationPath' {
229+
$gotPath =
230+
if ($psCmdlet.ParameterSetName -eq 'AreaPath') {
231+
Get-ADOAreaPath -Organization $Organization -Project $ProjectID -AreaPath $AreaPath
232+
} else {
233+
Get-ADOIterationPath -Organization $Organization -Project $ProjectID -IterationPath $iterationPath
234+
}
235+
236+
if (-not $gotPath) {
237+
continue
238+
}
239+
$PathIdList = @(
240+
$gotPath.Identifier
241+
$parentUri = $gotPath._links.parent.href
242+
while ($parentUri) {
243+
$parentPath = Invoke-ADORestAPI -Uri $parentUri
244+
$parentPath.identifier
245+
$parentUri = $parentPath._links.parent.href
246+
}
247+
)
248+
249+
[Array]::Reverse($PathIdList)
250+
251+
$null = $PSBoundParameters.Remove('ProjectID')
252+
253+
$q.Enqueue(@{
254+
NamespaceID =
255+
if ($psCmdlet.ParameterSetName -eq 'AreaPath') {
256+
'83e28ad4-2d72-4ceb-97b0-c7726d5502c3'
257+
} else {
258+
'bf7bfa03-b2b7-47db-8113-fa2e002cc5b1'
259+
}
260+
SecurityToken = @(foreach($PathId in $PathIdList) {
261+
"vstfs:///Classification/Node/$PathId"
262+
}) -join ':'
263+
} + $PSBoundParameters)
264+
}
265+
Analytics {
266+
$null = $PSBoundParameters.Remove('ProjectID')
267+
$q.Enqueue(@{
268+
NamespaceID = if ($ProjectID) { '58450c49-b02d-465a-ab12-59ae512d6531' } else { 'd34d3680-dfe5-4cc6-a949-7d9c68f73cba'}
269+
SecurityToken = "`$/$(if ($ProjectID) { $ProjectID } else { 'Shared' })"
270+
} + $PSBoundParameters)
271+
}
272+
Dashboard {
273+
$null = $PSBoundParameters.Remove('ProjectID')
274+
$q.Enqueue(@{
275+
NamespaceID = '8adf73b7-389a-4276-b638-fe1653f7efc7'
276+
SecurityToken = "$/$(if ($ProjectID) { $ProjectID })/$(if ($teamID) { $teamid } else { [guid]::Empty } )"
277+
} + $PSBoundParameters)
187278
}
188279
ProjectOverview {
189280
$null = $psboundParameters.Remove('Recurse')
190-
$q.Enqueue(@{
191-
ParameterSet='accesscontrollists/{NamespaceId}'
281+
$q.Enqueue(@{
192282
NamespaceID = '52d39943-cb85-4d7f-8fa8-c6baac873819' # Project permissions
193283
SecurityToken = "`$PROJECT:vstfs:///Classification/TeamProject/$ProjectID"
194284
} + $PSBoundParameters)
195-
$q.Enqueue(@{
196-
ParameterSet='accesscontrollists/{NamespaceId}'
285+
$q.Enqueue(@{
197286
NamespaceID = '2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87' # Repositories
198287
SecurityToken = "reposV2/$projectId"
199288
Recurse = $true
200289
} + $PSBoundParameters)
201-
$q.Enqueue(@{
202-
ParameterSet='accesscontrollists/{NamespaceId}'
290+
$q.Enqueue(@{
203291
NamespaceID = '33344d9c-fc72-4d6f-aba5-fa317101a7e9' # Build definitions
204292
SecurityToken = "$ProjectID/"
205293
Recurse = $true
206294
} + $PSBoundParameters)
207-
$q.Enqueue(@{
208-
ParameterSet='accesscontrollists/{NamespaceId}'
295+
$q.Enqueue(@{
209296
NamespaceID = 'c788c23e-1b46-4162-8f5e-d7585343b5de' # Releases
210297
SecurityToken = "$ProjectID/"
211298
Recurse = $true
212299
} + $PSBoundParameters)
213-
$q.Enqueue(@{
214-
ParameterSet='accesscontrollists/{NamespaceId}'
300+
$q.Enqueue(@{
215301
NamespaceID = '8adf73b7-389a-4276-b638-fe1653f7efc7' # Dashboards
216302
SecurityToken = "`$/$ProjectID/"
217303
Recurse = $true
218304
} + $PSBoundParameters)
219-
$q.Enqueue(@{
220-
ParameterSet='accesscontrollists/{NamespaceId}'
305+
$q.Enqueue(@{
221306
NamespaceID = '49b48001-ca20-4adc-8111-5b60c903a50c' # Service Endpoints
222307
SecurityToken = "endpoints/$ProjectID"
223308
Recurse = $true
224309
} + $PSBoundParameters)
225-
$q.Enqueue(@{
226-
ParameterSet='accesscontrollists/{NamespaceId}'
310+
$q.Enqueue(@{
227311
NamespaceID = 'cb594ebe-87dd-4fc9-ac2c-6a10a4c92046' # Service Hooks
228312
SecurityToken = "PublisherSecurity/$ProjectID"
229313
Recurse = $true
230314
} + $PSBoundParameters)
231315
}
316+
Plan {
317+
$q.Enqueue(@{
318+
NamespaceID = 'bed337f8-e5f3-4fb9-80da-81e17d06e7a8'
319+
SecurityToken = "Plan"
320+
} + $PSBoundParameters)
321+
}
232322
Tagging {
233323

234-
$q.Enqueue(@{
235-
ParameterSet='accesscontrollists/{NamespaceId}'
324+
$q.Enqueue(@{
236325
NamespaceID = 'bb50f182-8e5e-40b8-bc21-e8752a1e7ae2'
237326
SecurityToken = "/$ProjectID"
238327
} + $PSBoundParameters)
239328
}
240329
ManageTFVC {
241330

242-
$q.Enqueue(@{
243-
ParameterSet='accesscontrollists/{NamespaceId}'
331+
$q.Enqueue(@{
244332
NamespaceID = 'a39371cf-0841-4c16-bbd3-276e341bc052'
245333
SecurityToken = "/$ProjectID"
246334
} + $PSBoundParameters)
247335
}
248336
'BuildDefinition|BuildPermission' {
249337

250-
$q.Enqueue(@{
251-
ParameterSet='accesscontrollists/{NamespaceId}'
338+
$q.Enqueue(@{
252339
NamespaceID = 'a39371cf-0841-4c16-bbd3-276e341bc052'
253-
SecurityToken = "$ProjectID$(($path -replace '\\','/').TrimEnd('/'))/$DefinitionID"
340+
SecurityToken = "$ProjectID$(($buildpath -replace '\\','/').TrimEnd('/'))/$DefinitionID"
254341
} + $PSBoundParameters)
255-
$q.Enqueue(@{
256-
ParameterSet='accesscontrollists/{NamespaceId}'
342+
$q.Enqueue(@{
257343
NamespaceID = 'c788c23e-1b46-4162-8f5e-d7585343b5de'
258-
SecurityToken = "$ProjectID$(($path -replace '\\','/').TrimEnd('/'))/$DefinitionID"
344+
SecurityToken = "$ProjectID$(($buildpath -replace '\\','/').TrimEnd('/'))/$DefinitionID"
259345
} + $PSBoundParameters)
260346
}
261347
'RepositoryID|AllRepositories|ProjectRepository' {
262348

263-
$q.Enqueue(@{
264-
ParameterSet='accesscontrollists/{NamespaceId}'
349+
$q.Enqueue(@{
265350
NamespaceID = '2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87'
266351
SecurityToken = "repo$(
267352
if ($psCmdlet.ParameterSetName -eq 'AllRepositories') {'s'})V2$(

0 commit comments

Comments
 (0)