Skip to content

Commit 90745e3

Browse files
Set-ADOPermission: Now Supporting Addtional Easy Permissions:
* Analytics * Builds * AreaPaths (fixes #91) * Dashboards * IterationPaths Slight Internal Refactoring.
1 parent 799e755 commit 90745e3

File tree

1 file changed

+95
-9
lines changed

1 file changed

+95
-9
lines changed

Set-ADOPermission.ps1

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
Set-ADOPermission -Organization MyOrganization -Project MyProject -PersonalAccessToken $pat
1010
.Link
1111
https://docs.microsoft.com/en-us/rest/api/azure/devops/security/access%20control%20entries/set%20access%20control%20entries
12+
.Link
13+
https://docs.microsoft.com/en-us/azure/devops/organizations/security/namespace-reference
1214
#>
1315
[CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')]
1416
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("Test-ForParameterSetAmbiguity", "", Justification="Ambiguity Desired.")]
@@ -23,6 +25,10 @@
2325
# The Project ID.
2426
# If this is provided without anything else, will get permissions for the projectID
2527
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Project')]
28+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Analytics')]
29+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='AreaPath')]
30+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Dashboard')]
31+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='IterationPath')]
2632
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='Tagging')]
2733
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='ManageTFVC')]
2834
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildDefinition')]
@@ -33,6 +39,21 @@
3339
[string]
3440
$ProjectID,
3541

42+
# If provided, will set permissions related to a given teamID. ( see Get-ADOTeam)
43+
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='Dashboard')]
44+
[string]
45+
$TeamID,
46+
47+
# If provided, will set permissions related to an Area Path. ( see Get-ADOAreaPath )
48+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='AreaPath')]
49+
[string]
50+
$AreaPath,
51+
52+
# If provided, will set permissions related to an Iteration Path. ( see Get-ADOIterationPath )
53+
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='IterationPath')]
54+
[string]
55+
$IterationPath,
56+
3657
# The Build Definition ID
3758
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildDefinition')]
3859
[string]
@@ -41,7 +62,7 @@
4162
# The path to the build.
4263
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='BuildDefinition')]
4364
[string]
44-
$Path ='/',
65+
$BuildPath ='/',
4566

4667
# If set, will set build and release permissions for a given project.
4768
[Parameter(Mandatory,ValueFromPipelineByPropertyName,ParameterSetName='BuildPermission')]
@@ -184,32 +205,97 @@
184205
$ProgressPreference = $oldProgressPref
185206
if (-not $ProjectID) { return }
186207
}
208+
$psBoundParameters['ParameterSet']='accesscontrolentries/{NamespaceId}'
187209
switch -Regex ($psCmdlet.ParameterSetName) {
188210
Project {
189211
$null = $PSBoundParameters.Remove('ProjectID')
190-
$q.Enqueue(@{
191-
ParameterSet='accesscontrolentries/{NamespaceId}'
212+
$q.Enqueue(@{
192213
NamespaceID = '52d39943-cb85-4d7f-8fa8-c6baac873819'
193214
SecurityToken = "`$PROJECT:vstfs:///Classification/TeamProject/$ProjectID"
194215
} + $PSBoundParameters)
195216
}
217+
Analytics {
218+
$null = $PSBoundParameters.Remove('ProjectID')
219+
$q.Enqueue(@{
220+
NamespaceID = if ($ProjectID) { '58450c49-b02d-465a-ab12-59ae512d6531' } else { 'd34d3680-dfe5-4cc6-a949-7d9c68f73cba'}
221+
SecurityToken = "`$/$(if ($ProjectID) { $ProjectID } else { 'Shared' })"
222+
} + $PSBoundParameters)
223+
}
224+
'AreaPath|IterationPath' {
225+
$gotPath =
226+
if ($psCmdlet.ParameterSetName -eq 'AreaPath') {
227+
Get-ADOAreaPath -Organization $Organization -Project $ProjectID -AreaPath $AreaPath
228+
} else {
229+
Get-ADOIterationPath -Organization $Organization -Project $ProjectID -IterationPath $iterationPath
230+
}
231+
232+
if (-not $gotPath) {
233+
continue
234+
}
235+
$PathIdList = @(
236+
$gotPath.Identifier
237+
$parentUri = $gotPath._links.parent.href
238+
while ($parentUri) {
239+
$parentPath = Invoke-ADORestAPI -Uri $parentUri
240+
$parentPath.identifier
241+
$parentUri = $parentPath._links.parent.href
242+
}
243+
)
244+
245+
[Array]::Reverse($PathIdList)
246+
247+
$null = $PSBoundParameters.Remove('ProjectID')
248+
249+
$q.Enqueue(@{
250+
NamespaceID =
251+
if ($psCmdlet.ParameterSetName -eq 'AreaPath') {
252+
'83e28ad4-2d72-4ceb-97b0-c7726d5502c3'
253+
} else {
254+
'bf7bfa03-b2b7-47db-8113-fa2e002cc5b1'
255+
}
256+
SecurityToken = @(foreach($PathId in $PathIdList) {
257+
"vstfs:///Classification/Node/$PathId"
258+
}) -join ':'
259+
} + $PSBoundParameters)
260+
}
261+
Dashboard {
262+
$null = $PSBoundParameters.Remove('ProjectID')
263+
$q.Enqueue(@{
264+
NamespaceID = '8adf73b7-389a-4276-b638-fe1653f7efc7'
265+
SecurityToken = "$/$(if ($ProjectID) { $ProjectID })/$(if ($teamID) { $teamid } else { [guid]::Empty } )"
266+
} + $PSBoundParameters)
267+
}
268+
Plan {
269+
$q.Enqueue(@{
270+
NamespaceID = 'bed337f8-e5f3-4fb9-80da-81e17d06e7a8'
271+
SecurityToken = "Plan"
272+
} + $PSBoundParameters)
273+
}
196274
Tagging {
197-
$q.Enqueue(@{
198-
ParameterSet='accesscontrolentries/{NamespaceId}'
275+
$q.Enqueue(@{
199276
NamespaceID = 'bb50f182-8e5e-40b8-bc21-e8752a1e7ae2'
200277
SecurityToken = "/$ProjectID"
201278
} + $PSBoundParameters)
202279
}
203280
ManageTFVC {
204-
$q.Enqueue(@{
205-
ParameterSet='accesscontrolentries/{NamespaceId}'
281+
$q.Enqueue(@{
206282
NamespaceID = 'a39371cf-0841-4c16-bbd3-276e341bc052'
207283
SecurityToken = "/$ProjectID"
208284
} + $PSBoundParameters)
209285
}
286+
'BuildDefinition|BuildPermission' {
287+
288+
$q.Enqueue(@{
289+
NamespaceID = 'a39371cf-0841-4c16-bbd3-276e341bc052'
290+
SecurityToken = "$ProjectID$(($BuildPath -replace '\\','/').TrimEnd('/'))/$DefinitionID"
291+
} + $PSBoundParameters)
292+
$q.Enqueue(@{
293+
NamespaceID = 'c788c23e-1b46-4162-8f5e-d7585343b5de'
294+
SecurityToken = "$ProjectID$(($BuildPath -replace '\\','/').TrimEnd('/'))/$DefinitionID"
295+
} + $PSBoundParameters)
296+
}
210297
'RepositoryID|AllRepositories|ProjectRepository' {
211-
$q.Enqueue(@{
212-
ParameterSet='accesscontrolentries/{NamespaceId}'
298+
$q.Enqueue(@{
213299
NamespaceID = '2e9eb7ed-3c0a-47d4-87c1-0ffdd275fd87'
214300
SecurityToken = "repo$(
215301
if ($psCmdlet.ParameterSetName -eq 'AllRepositories') {'s'})V2$(

0 commit comments

Comments
 (0)