Skip to content

Commit c9b6857

Browse files
author
SimonDeeb
committed
add teams cmdlets
1 parent b0000d6 commit c9b6857

13 files changed

Lines changed: 1030 additions & 199 deletions

AzureDevOpsPowerShell/Public/Api/Work/Teams/Get-AzDoTeamSettings.ps1 renamed to AzureDevOpsPowerShell/Public/Api/Core/TeamSettings/Get-AzDoTeamSettings.ps1

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,20 @@ function Get-AzDoTeamSettings {
1414
Get-AzDoTeamSettings @Params
1515
1616
This example will get the settings of the team 'Team1' in the project 'Playground'.
17-
.EXAMPLE
18-
$Params = @{
19-
CollectionUri = "https://dev.azure.com/cantoso"
20-
ProjectName = "Playground"
21-
}
22-
23-
Get-AzDoTeamSettings @Params
24-
25-
This example will get the settings of all the teams in the project 'Playground'.
2617
.OUTPUTS
2718
PSObject with the settings of the team(s).
2819
#>
2920

3021
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
3122
param (
3223
# Collection Uri of the organization
33-
[Parameter(Mandatory)]
24+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
3425
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
3526
[string]
3627
$CollectionUri,
3728

3829
# Name of the project where the team is located
39-
[Parameter(Mandatory)]
30+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
4031
[string]
4132
$ProjectName,
4233

@@ -65,7 +56,7 @@ function Get-AzDoTeamSettings {
6556
try {
6657
$result += Invoke-AzDoRestMethod @params
6758
} catch {
68-
Write-Error $_.Exception.Message
59+
Write-AzdoError -Message $_
6960
}
7061
} else {
7162
Write-Verbose "Skipping team settings for team '$Name' in project '$ProjectName'."
@@ -80,7 +71,8 @@ function Get-AzDoTeamSettings {
8071
TeamId = ($_.url -split '/')[-4]
8172
BacklogIteration = $_.backlogIteration
8273
BacklogVisibilities = $_.backlogVisibilities
83-
DefualtIterationMacro = $_.defaultIterationMacro
74+
DefualtIteration = $_.defaultIteration
75+
DefaultIterationMacro = $_.defaultIterationMacro
8476
WorkingDays = $_.workingDays
8577
BugsBehavior = $_.bugsBehavior
8678
Url = $_.url
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
function Set-AzDoTeamSettings {
2+
<#
3+
.SYNOPSIS
4+
Set the settings of a Team in Azure DevOps.
5+
.DESCRIPTION
6+
Set the settings of a Team or multiple in Azure DevOps.
7+
.EXAMPLE
8+
$Params = @{
9+
CollectionUri = "https://dev.azure.com/cantoso"
10+
ProjectName = "Playground"
11+
TeamName = "Team1"
12+
BacklogIteration = "323b04b6-2fb8-4093-94f4-fbe3bd36a19f"
13+
DefaultIteration = "8c2457e8-8936-4cdc-b3aa-17b20f56c76c"
14+
BugsBehavior = "off"
15+
WorkingDays = @("monday", "tuesday", "wednesday", "thursday", "friday")
16+
Iterations = @(
17+
"8c2457e8-8936-4cdc-b3aa-17b20f56c76c",
18+
"323b04b6-2fb8-4093-94f4-fbe3bd36a19f"
19+
)
20+
AreaPath = "ProjectName"
21+
IncludeAreaChildren = $true
22+
}
23+
24+
Set-AzDoTeamSettings @Params
25+
26+
This example will set the settings of the team 'Team1' in the project 'Playground'.
27+
#>
28+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
29+
param(
30+
# Collection Uri of the organization
31+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
32+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
33+
[string]
34+
$CollectionUri,
35+
36+
# Name of the project where the team is located
37+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
38+
[string]
39+
$ProjectName,
40+
41+
# Name of the team to get the settings from
42+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
43+
[string]
44+
$TeamName,
45+
46+
# Backlog iteration id
47+
[Parameter(ValueFromPipelineByPropertyName)]
48+
[string]
49+
$BacklogIteration,
50+
51+
# Bugs behavior
52+
[Parameter(ValueFromPipelineByPropertyName)]
53+
[ValidateSet('off', 'asRequirements', 'asTasks')]
54+
[string]
55+
$BugsBehavior,
56+
57+
# Working days
58+
[Parameter(ValueFromPipelineByPropertyName)]
59+
[ValidateSet('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday')]
60+
[string[]]
61+
$WorkingDays,
62+
63+
# Iteration paths
64+
[Parameter(ValueFromPipelineByPropertyName)]
65+
[string[]]
66+
$Iterations,
67+
68+
# Area path
69+
[Parameter(ValueFromPipelineByPropertyName)]
70+
[string]
71+
$AreaPath,
72+
73+
# Include area children
74+
[Parameter(ValueFromPipelineByPropertyName)]
75+
[bool]
76+
$IncludeAreaChildren = $true
77+
)
78+
79+
begin {
80+
Write-Verbose "Starting function: Set-AzDoTeamSettings"
81+
}
82+
83+
process {
84+
$Team = Get-AzDoTeam -CollectionUri $CollectionUri -ProjectName $ProjectName -TeamName $TeamName -ErrorAction SilentlyContinue
85+
if ($Team) {
86+
# Set the team settings
87+
$Settings = @{}
88+
if ($BacklogIteration) {
89+
$Settings.backlogIteration = $BacklogIteration
90+
}
91+
if ($BugsBehavior) {
92+
$Settings.bugsBehavior = $BugsBehavior
93+
}
94+
if ($WorkingDays) {
95+
$Settings.workingDays = $WorkingDays
96+
}
97+
$SettingsParams = @{
98+
uri = "$CollectionUri/$ProjectName/$TeamName/_apis/work/teamSettings"
99+
method = 'PATCH'
100+
version = '7.1-preview.1'
101+
body = $Settings
102+
}
103+
try {
104+
Write-Verbose "Setting team settings for team '$TeamName' in project '$ProjectName'."
105+
$SettingsResult = Invoke-AzDoRestMethod @SettingsParams
106+
} catch {
107+
Write-AzdoError -Message $_
108+
}
109+
110+
# Set the area path
111+
if ($AreaPath) {
112+
$AreaParams = @{
113+
uri = "$CollectionUri/$ProjectName/$TeamName/_apis/work/teamsettings/teamfieldvalues"
114+
method = 'PATCH'
115+
version = '7.1-preview.1'
116+
body = @{
117+
defaultValue = "$ProjectName\\$AreaPath"
118+
values = @(
119+
@{
120+
includeChildren = $IncludeAreaChildren
121+
value = "$ProjectName\\$AreaPath"
122+
}
123+
)
124+
}
125+
}
126+
try {
127+
Write-Verbose "Setting area path for team '$TeamName' in project '$ProjectName'."
128+
$AreaResult = Invoke-AzDoRestMethod @AreaParams
129+
} catch {
130+
Write-AzdoError -Message $_
131+
}
132+
}
133+
134+
# Set the iteration paths
135+
$IterationResult = @()
136+
foreach ($Iteration in $Iterations) {
137+
$IterationParams = @{
138+
uri = "$CollectionUri/$ProjectName/$TeamName/_apis/work/teamsettings/iterations"
139+
method = 'POST'
140+
version = '7.1-preview.1'
141+
body = @{ id = $Iteration }
142+
}
143+
try {
144+
Write-Verbose "Setting iteration paths for team '$TeamName' in project '$ProjectName'."
145+
$IterationResult += Invoke-AzDoRestMethod @IterationParams
146+
} catch {
147+
Write-AzdoError -Message $_
148+
}
149+
}
150+
151+
$result += [PSCustomObject]@{
152+
CollectionUri = $CollectionUri
153+
ProjectName = $ProjectName
154+
TeamName = $TeamName
155+
BacklogIteration = $SettingsResult.backlogIteration
156+
BugsBehavior = $SettingsResult.bugsBehavior
157+
WorkingDays = $SettingsResult.workingDays
158+
AreaPath = $AreaResult.defaultValue
159+
IncludeAreaChildren = $AreaResult.values.includeChildren
160+
Iterations = $IterationResult
161+
}
162+
} else {
163+
Write-Host "Team '$TeamName' not found in project '$ProjectName', skipping."
164+
}
165+
}
166+
167+
end {
168+
if ($result) {
169+
$result
170+
}
171+
Write-Verbose "Ending function: Set-AzDoTeamSettings"
172+
}
173+
}

AzureDevOpsPowerShell/Public/Api/Work/Teams/Get-AzDoTeam.ps1 renamed to AzureDevOpsPowerShell/Public/Api/Core/Teams/Get-AzDoTeam.ps1

File renamed without changes.

AzureDevOpsPowerShell/Public/Api/Work/Teams/New-AzDoTeam.ps1 renamed to AzureDevOpsPowerShell/Public/Api/Core/Teams/New-AzDoTeam.ps1

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,50 @@
11
function New-AzDoTeam {
2+
<#
3+
.SYNOPSIS
4+
Create a new team in a project.
5+
6+
.DESCRIPTION
7+
Create a new team in a project.
8+
9+
.EXAMPLE
10+
$Params = @{
11+
CollectionUri = "https://dev.azure.com/contoso"
12+
ProjectName = "Project 1"
13+
TeamName = "Team 1"
14+
}
15+
New-AzDoTeam @Params
16+
17+
This example will create a new team named 'Team 1' in 'Project 1'.
18+
19+
.EXAMPLE
20+
$Params = @{
21+
CollectionUri = "https://dev.azure.com/contoso"
22+
ProjectName = "Project 1"
23+
TeamName = "Team 1", "Team 2"
24+
Description = "Team 1 description", "Team 2 description"
25+
}
26+
New-AzDoTeam @Params
27+
28+
This example will create two new teams named 'Team 1' and 'Team 2' in 'Project 1' with the descriptions 'Team 1 description' and 'Team 2 description' respectively.
29+
30+
.NOTES
31+
Additional information about the function.
32+
#>
233
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')]
334
param (
435
# Collection Uri of the organization
5-
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
36+
[Parameter(Mandatory)]
637
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
738
[string]
839
$CollectionUri,
940

1041
# Name of the project where the team is located
11-
[Parameter(ValueFromPipelineByPropertyName)]
42+
[Parameter(Mandatory)]
1243
[string]
1344
$ProjectName,
1445

1546
# Name of the team to create
16-
[Parameter(ValueFromPipelineByPropertyName)]
47+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
1748
[string[]]
1849
$TeamName,
1950

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
function Remove-AzDoTeam {
2+
param (
3+
# Collection Uri of the organization
4+
[Parameter(Mandatory)]
5+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
6+
[string]
7+
$CollectionUri,
8+
9+
# Name of the project where the team is located
10+
[Parameter(Mandatory)]
11+
[string]
12+
$ProjectName,
13+
14+
# Name(s) of the team(s) to delete
15+
[Parameter(ValueFromPipelineByPropertyName)]
16+
[string[]]
17+
$TeamName,
18+
19+
# Id(s) of the team(s) to delete
20+
[Parameter(ValueFromPipelineByPropertyName)]
21+
[string[]]
22+
$TeamId
23+
)
24+
25+
begin {
26+
Write-Verbose "Starting function: Remove-AzDoTeam"
27+
}
28+
29+
process {
30+
if ($TeamName) {
31+
$TeamId = foreach ($Name in $TeamName) {
32+
Get-AzDoTeam -CollectionUri $CollectionUri -ProjectName $ProjectName -TeamName $Name -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Id
33+
}
34+
}
35+
36+
foreach ($Id in $TeamId) {
37+
$params = @{
38+
uri = "$CollectionUri/_apis/projects/$ProjectName/teams/$Id"
39+
method = 'DELETE'
40+
version = '7.1-preview.3'
41+
}
42+
43+
if ($PSCmdlet.ShouldProcess("Delete team '$Id' in project '$ProjectName'")) {
44+
try {
45+
Invoke-AzDoRestMethod @params
46+
} catch {
47+
Write-AzdoError -Message $_
48+
}
49+
} else {
50+
Write-Verbose "Skipping team '$Id' in project '$ProjectName'."
51+
}
52+
}
53+
54+
}
55+
end {
56+
Write-Verbose "Ending function: Remove-AzDoTeam"
57+
}
58+
}

AzureDevOpsPowerShell/Public/Api/Work/Teams/Set-AzDoTeamArea.ps1

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)