Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AzureDevOpsPowerShell/Private/Invoke-AzDoRestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function Invoke-AzDoRestMethod {
try {
Invoke-RestMethod @params
} catch {
Write-AzdoError -Message ($_ | ConvertFrom-Json).message
$PSCmdlet.ThrowTerminatingError((Write-AzDoError -Message ($_ | ConvertFrom-Json).message))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion AzureDevOpsPowerShell/Private/Validate-CollectionUri.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function Validate-CollectionUri {
)

if ($CollectionUri -notmatch '^https:\/\/dev\.azure\.com\/\w+') {
Write-AzdoError "CollectionUri must be a valid Azure DevOps collection URI starting with 'https://dev.azure.com/'"
$PSCmdlet.ThrowTerminatingError((Write-AzDoError "CollectionUri must be a valid Azure DevOps collection URI starting with 'https://dev.azure.com/'"))
} else {
$true
}
Expand Down
4 changes: 1 addition & 3 deletions AzureDevOpsPowerShell/Private/Write-AzDoError.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ function Write-AzDoError {


process {
$errorRec = [System.Management.Automation.ErrorRecord]::new(
[System.Management.Automation.ErrorRecord]::new(
[Exception]::new($Message),
'ErrorID',
[System.Management.Automation.ErrorCategory]::OperationStopped,
'TargetObject'
)

$PScmdlet.ThrowTerminatingError($errorRec)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function New-AzDoProject {
if ($_ -match 'TF200019') {
Write-Warning "Project $name already exists, trying to get it"
} else {
Write-AzDoError -message $_
$PSCmdlet.ThrowTerminatingError((Write-AzDoError -message $_))
}
}

Expand Down
93 changes: 93 additions & 0 deletions AzureDevOpsPowerShell/Public/Api/Core/Teams/Get-AzDoAllTeams.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
function Get-AzDoAllTeams {
<#
.SYNOPSIS
This script gets all teams within an organization.
.DESCRIPTION
This script retrieves all teams within an organization using the Azure DevOps REST API.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contoso/'
ExpandIdentity = $true
Mine = $true
}
Get-AzDoAllTeams @params

This example gets all teams within 'contoso' where the requesting user is a member.
.OUTPUTS
PSObject
.NOTES
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection URI. e.g. https://dev.azure.com/contoso.
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[String]
$CollectionUri,

# Whether or not to return detailed identity info
[Parameter(ValueFromPipelineByPropertyName)]
[Switch]
$ExpandIdentity = $false,

# Filter only teams your identity is member of
[Parameter(ValueFromPipelineByPropertyName)]
[Switch]
$Mine = $false,

# Skip number N of results
[Parameter(ValueFromPipelineByPropertyName)]
[Int]
$Skip = 0,

# Show only top N results
[Parameter(ValueFromPipelineByPropertyName)]
[Int]
$Top = 0
)
process {
$result = @()
Write-Verbose "Starting function: Get-AzDoAllTeams"

$queryParams = @()
if ($ExpandIdentity) {
$queryParams += "`$expandIdentity=$ExpandIdentity"
}
if ($Mine) {
$queryParams += "`$mine=$Mine"
}
if ($Skip -gt 0) {
$queryParams += "`$skip=$Skip"
}
if ($Top -gt 0) {
$queryParams += "`$top=$Top"
}
$queryParams = $queryParams -join "&"

$uri = "$CollectionUri/_apis/teams"
$version = "7.1-preview.3"

$params = @{
Uri = $uri
Version = $version
QueryParameters = $queryParams
Method = 'GET'
}

if ($PSCmdlet.ShouldProcess($CollectionUri, "Get all teams in organization")) {
(Invoke-AzDoRestMethod @params).value | ForEach-Object {
[PSCustomObject]@{
CollectionUri = $CollectionUri
ProjectName = $_.projectName
TeamName = $_.name
TeamId = $_.id
Description = $_.description
Url = $_.url
IdentityUrl = $_.identityUrl
}
}
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
function Get-AzDoProjectTeam {
<#
.SYNOPSIS
This script gets team details in a given project.
.DESCRIPTION
This script gets teams in a given project.
When used in a pipeline, you can use the pre-defined CollectionUri, ProjectName, and AccessToken (PAT) variables.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contoso/'
ProjectName = 'Project 1'
TeamName = 'testteam'
}
Get-AzDoProjectTeam @params

This example gets the team 'testteam' in 'Project 1'.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contoso/'
ProjectName = 'Project 1'
}
Get-AzDoProjectTeam @params

This example gets all teams in 'Project 1'.
.OUTPUTS
PSObject
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection URI
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,

# Project name of the project
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$ProjectName,

# team name
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$TeamName
)
process {
Write-Verbose "Starting function: Get-AzDoProjectTeam"

$params = @{
uri = "$CollectionUri/_apis/projects/$ProjectName/teams"
version = "7.1-preview.3"
method = 'GET'
}
if ($PSCmdlet.ShouldProcess($CollectionUri, "Get teams from: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
try {
$teams = (Invoke-AzDoRestMethod @params).value
} catch {
$PSCmdlet.ThrowTerminatingError((Write-AzDoError -message "Failed to get teams for project '$ProjectName'. Error: $_"))
}
if ($TeamName) {
$teams | Where-Object { $_.name -eq $TeamName } | ForEach-Object {
[PSCustomObject]@{
CollectionURI = $CollectionUri
ProjectName = $ProjectName
TeamName = $_.name
TeamId = $_.id
Description = $_.description
Url = $_.url
IdentityUrl = $_.identityUrl
}
}
} else {
$teams | ForEach-Object {
[PSCustomObject]@{
CollectionURI = $CollectionUri
ProjectName = $ProjectName
TeamName = $_.name
TeamId = $_.id
Description = $_.description
Url = $_.url
IdentityUrl = $_.identityUrl
}
}
}
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)"
}
}
}

95 changes: 95 additions & 0 deletions AzureDevOpsPowerShell/Public/Api/Core/Teams/Get-AzDoTeamMember.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
function Get-AzDoTeamMember {
<#
.SYNOPSIS
This script gets team members with extended properties in a given project and team.
.DESCRIPTION
This script gets team members with extended properties in a given project and team.
When used in a pipeline, you can use the pre-defined CollectionUri, ProjectName, and AccessToken (PAT) variables.
.EXAMPLE
$params = @{
CollectionUri = 'https://dev.azure.com/contos0'
ProjectName = 'Project 1'
TeamName = 'testteam'
}
Get-AzDoTeamMember @params

This example gets the team members with extended properties in 'testteam' within 'Project 1'.
.OUTPUTS
PSObject
.NOTES
#>
[CmdletBinding(SupportsShouldProcess)]
param (
# Collection Uri of the organization
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[ValidateScript({ Validate-CollectionUri -CollectionUri $_ })]
[string]
$CollectionUri,

# the projectName
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$ProjectName,

# Team name of the team
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[string]
$TeamName
)

process {
Write-Verbose "Starting function: Get-AzDoTeamMember"

# Get the team ID using the Get-AzDoProjectTeam function
$teamParams = @{
CollectionUri = $CollectionUri
ProjectName = $ProjectName
TeamName = $TeamName
}

try {
$team = Get-AzDoProjectTeam @teamParams | Where-Object { $_.TeamName -eq $TeamName }
if (-not $team) {
throw "Team '$TeamName' not found in project '$ProjectName'."
}

$teamId = $team.TeamId
Write-Verbose "Retrieved Team ID: $teamId"
} catch {
$PSCmdlet.ThrowTerminatingError((Write-AzDoError "Team '$TeamName' not found in project '$ProjectName'. Error: $_"))
}

$params = @{
uri = "$CollectionUri/_apis/projects/$ProjectName/teams/$teamId/members"
version = "7.1-preview.2"
method = 'GET'
}

Write-Verbose "Request URI: $($params.uri)"

if ($PSCmdlet.ShouldProcess($CollectionUri, "Get team members with extended properties from: $($PSStyle.Bold)$TeamName$($PSStyle.Reset) in project: $($PSStyle.Bold)$ProjectName$($PSStyle.Reset)")) {
try {
$members = (Invoke-AzDoRestMethod @params).value
if (-not $members) {
Write-Verbose "No members found for team '$TeamName'."
} else {
$members | ForEach-Object {
[PSCustomObject]@{
CollectionUri = $CollectionUri
TeamName = $TeamName
ProjectName = $ProjectName
MemberId = $_.identity.id
DisplayName = $_.identity.displayName
UniqueName = $_.identity.uniqueName
IsTeamAdmin = $_.isTeamAdmin ? $true : $false
}
}
}
} catch {
$PSCmdlet.ThrowTerminatingError((Write-AzDoError "Error retrieving team members for '$TeamName' Error: $_"))
}
} else {
Write-Verbose "Calling Invoke-AzDoRestMethod with $($params | ConvertTo-Json -Depth 10)"
}
}
}
Loading
Loading