Skip to content

Commit 133459d

Browse files
author
SimonDeeb
committed
feat: Add support for Teams and WorkItems cmdlets
1 parent f01d975 commit 133459d

21 files changed

Lines changed: 2323 additions & 0 deletions
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
function Get-AzDoTeamSettings {
2+
<#
3+
.SYNOPSIS
4+
Get the settings of a Team in Azure DevOps.
5+
.DESCRIPTION
6+
Get 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+
}
13+
14+
Get-AzDoTeamSettings @Params
15+
16+
This example will get the settings of the team 'Team1' in the project 'Playground'.
17+
.OUTPUTS
18+
PSObject with the settings of the team(s).
19+
#>
20+
21+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
22+
param (
23+
# Collection Uri of the organization
24+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
25+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
26+
[string]
27+
$CollectionUri,
28+
29+
# Name of the project where the team is located
30+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
31+
[string]
32+
$ProjectName,
33+
34+
# Name of the team to get the settings from
35+
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
36+
[string[]]
37+
$TeamName
38+
)
39+
40+
begin {
41+
Write-Verbose "Starting function: Get-AzDoTeamSettings"
42+
$CollectionUri = $CollectionUri.TrimEnd('/')
43+
# create dynamic array to store the results
44+
$result = New-Object System.Collections.Generic.List[System.Object]
45+
}
46+
47+
process {
48+
foreach ($Name in $TeamName) {
49+
$params = @{
50+
uri = "$CollectionUri/$ProjectName/$Name/_apis/work/teamSettings"
51+
method = 'GET'
52+
version = '7.1-preview.1'
53+
}
54+
55+
if ($PSCmdlet.ShouldProcess("Get team settings for team '$Name' in project '$ProjectName'")) {
56+
try {
57+
$result += Invoke-AzDoRestMethod @params
58+
} catch {
59+
Write-AzdoError -Message $_
60+
}
61+
} else {
62+
Write-Verbose "Skipping team settings for team '$Name' in project '$ProjectName'."
63+
}
64+
}
65+
}
66+
67+
end {
68+
if ($result) {
69+
$result | ForEach-Object {
70+
[PSCustomObject]@{
71+
TeamId = ($_.url -split '/')[-4]
72+
BacklogIteration = $_.backlogIteration
73+
BacklogVisibilities = $_.backlogVisibilities
74+
DefualtIteration = $_.defaultIteration
75+
DefaultIterationMacro = $_.defaultIterationMacro
76+
WorkingDays = $_.workingDays
77+
BugsBehavior = $_.bugsBehavior
78+
Url = $_.url
79+
}
80+
}
81+
}
82+
}
83+
}
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+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
function Get-AzDoTeam {
2+
<#
3+
.SYNOPSIS
4+
Gets information about a team in Azure DevOps.
5+
.DESCRIPTION
6+
Gets information about 1 team if the parameter $TeamName is filled in. Otherwise it will list all the teams's.
7+
.EXAMPLE
8+
$Params = @{
9+
CollectionUri = "https://dev.azure.com/contoso"
10+
}
11+
Get-AzDoTeam -CollectionUri = "https://dev.azure.com/contoso"
12+
13+
This example will list all the teams in the organization.
14+
.EXAMPLE
15+
$Params = @{
16+
CollectionUri = "https://dev.azure.com/contoso"
17+
ProjectName = "Project 1"
18+
}
19+
Get-AzDoTeam -CollectionUri = "https://dev.azure.com/contoso" -ProjectName = "Project 1"
20+
21+
This example will list all the teams contained in 'Project 1'.
22+
.EXAMPLE
23+
$Params = @{
24+
CollectionUri = "https://dev.azure.com/contoso"
25+
TeamName "Team 1"
26+
}
27+
Get-AzDoTeam -CollectionUri = "https://dev.azure.com/contoso" -TeamName "Team 1"
28+
29+
This example will fetch information about the team with the name 'Team 1'.
30+
.EXAMPLE
31+
$Params = @{
32+
CollectionUri = "https://dev.azure.com/contoso"
33+
TeamId "564e8204-a90b-4432-883b-d4363c6125ca"
34+
}
35+
Get-AzDoTeam -CollectionUri = "https://dev.azure.com/contoso" -TeamId "564e8204-a90b-4432-883b-d4363c6125ca"
36+
37+
This example will fetch information about the team with the ID '564e8204-a90b-4432-883b-d4363c6125ca'.
38+
.OUTPUTS
39+
PSObject with team(s).
40+
41+
#>
42+
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Low')]
43+
param (
44+
# Collection Uri of the organization
45+
[Parameter(Mandatory)]
46+
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
47+
[string]
48+
$CollectionUri,
49+
50+
# Name of the project where the team is located
51+
[Parameter(ValueFromPipelineByPropertyName)]
52+
[string]
53+
$ProjectName,
54+
55+
# Name of the team to fetch
56+
[Parameter(ValueFromPipelineByPropertyName)]
57+
[string[]]
58+
$TeamName,
59+
60+
# Id of the team to fetch
61+
[Parameter(ValueFromPipelineByPropertyName)]
62+
[string]
63+
$TeamId
64+
)
65+
66+
begin {
67+
Write-Verbose "Starting function: Get-AzDoTeam"
68+
}
69+
70+
process {
71+
$params = @{
72+
uri = "$CollectionUri/_apis/teams"
73+
version = "7.1-preview.3"
74+
method = 'GET'
75+
}
76+
77+
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get Teams from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
78+
$teams = (Invoke-AzDoRestMethod @params).value
79+
80+
# Filter the teams if the parameters are filled in
81+
if ($TeamName) {
82+
$teams = $teams | Where-Object { $_.name -eq $TeamName }
83+
}
84+
if ($ProjectName) {
85+
$teams = $teams | Where-Object { $_.projectName -eq $ProjectName }
86+
}
87+
if ($TeamId) {
88+
$teams = $teams | Where-Object { $_.id -eq $TeamId }
89+
}
90+
$result = $teams
91+
} else {
92+
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params| ConvertTo-Json -Depth 10)"
93+
}
94+
}
95+
96+
end {
97+
if ($result) {
98+
$result | ForEach-Object {
99+
[PSCustomObject]@{
100+
CollectionURI = $CollectionUri
101+
ProjectName = $ProjectName
102+
TeamName = $_.name
103+
TeamId = $_.id
104+
}
105+
}
106+
} else {
107+
Write-Host "No teams found"
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)