Skip to content
Merged
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ All notable changes to this project will be documented in this file.

<br> -->

## [UNRELEASED]

### Summary
- _None_

### What's Changed
- feat(Get-AdoMembership): Add list support

### Breaking Changes
- _None_

<br>

## [0.4.1] - 2026-02-17

### Summary
Expand Down
108 changes: 100 additions & 8 deletions docs/Get-AdoMembership.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,33 @@ title: Get-AdoMembership

## SYNOPSIS

Get the membership relationship between a subject and a container in Azure DevOps.
Get membership relationships

## SYNTAX

### __AllParameterSets
### GetMembership

```text
Get-AdoMembership [[-CollectionUri] <string>] [-SubjectDescriptor] <string[]>
[-ContainerDescriptor] <string> [[-Version] <string>] [<CommonParameters>]
```

### ListMemberships

```text
Get-AdoMembership [[-CollectionUri] <string>] [-SubjectDescriptor] <string[]>
[[-Depth] <int32>] [[-Direction] <string>] [[-Version] <string>] [<CommonParameters>]
```

## ALIASES

This cmdlet has the following aliases,
- N/A

## DESCRIPTION

This cmdlet retrieves the membership relationship between a specified subject and container in Azure DevOps.
This cmdlet retrieves the membership relationships between a specified subject and container in Azure DevOps or
get all the memberships where this descriptor is a member in the relationship.

## EXAMPLES

Expand Down Expand Up @@ -64,6 +72,38 @@ $params = @{

Retrieves the membership relationships for multiple subjects demonstrating pipeline input.

### EXAMPLE 3

#### PowerShell

```powershell
$params = @{
CollectionUri = 'https://vssps.dev.azure.com/my-org'
SubjectDescriptor = 'aadgp.00000000-0000-0000-0000-000000000000'
Depth = 2
Direction = 'up'
}
Get-AdoMembership @params
```

Retrieves all groups for a user with a depth of 2.

### EXAMPLE 4

#### PowerShell

```powershell
$params = @{
CollectionUri = 'https://vssps.dev.azure.com/my-org'
SubjectDescriptor = 'aadgp.00000000-0000-0000-0000-000000000000'
Depth = 2
Direction = 'down'
}
Get-AdoMembership @params
```

Retrieves all memberships of a group with a depth of 2.

## PARAMETERS

### -CollectionUri
Expand Down Expand Up @@ -112,7 +152,7 @@ HelpMessage: ''

### -ContainerDescriptor

Mandatory.
Optional.
A descriptor to the container in the relationship.

```yaml
Expand All @@ -121,9 +161,32 @@ DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
- Name: GetMembership
Position: Named
IsRequired: true
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### -Depth

Optional.
The depth of memberships to retrieve when ContainerDescriptor is not specified.
Default is 1.

```yaml
Type: System.Int32
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: ListMemberships
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
Expand All @@ -132,15 +195,42 @@ AcceptedValues: []
HelpMessage: ''
```

### -Direction

Optional.
The direction of memberships to retrieve when ContainerDescriptor is not specified.

The default value for direction is 'up' meaning return all memberships where the subject is a member (e.g. all groups the subject is a member of).
Alternatively, passing the direction as 'down' will return all memberships where the subject is a container (e.g. all members of the subject group).

```yaml
Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: ListMemberships
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues:
- up
- down
HelpMessage: ''
```

### -Version

Optional.
The API version to use for the request.
Default is '7.2-preview.1'.
Default is '7.1-preview.1'.

```yaml
Type: System.String
DefaultValue: 7.2-preview.1
DefaultValue: 7.1-preview.1
SupportsWildcards: false
Aliases:
- ApiVersion
Expand All @@ -153,6 +243,7 @@ ParameterSets:
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues:
- 7.1-preview.1
- 7.2-preview.1
HelpMessage: ''
```
Expand Down Expand Up @@ -180,3 +271,4 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
## RELATED LINKS

- <https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/memberships/get>
- <https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/memberships/list>
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
function Get-AdoMembership {
<#
.SYNOPSIS
Get the membership relationship between a subject and a container in Azure DevOps.
Get membership relationships

.DESCRIPTION
This cmdlet retrieves the membership relationship between a specified subject and container in Azure DevOps.
This cmdlet retrieves the membership relationships between a specified subject and container in Azure DevOps or
get all the memberships where this descriptor is a member in the relationship.

.PARAMETER CollectionUri
Optional. The collection URI of the Azure DevOps collection/organization, e.g., https://vssps.dev.azure.com/my-org.
Expand All @@ -13,16 +14,26 @@
Mandatory. A descriptor to the child subject in the relationship.

.PARAMETER ContainerDescriptor
Mandatory. A descriptor to the container in the relationship.
Optional. A descriptor to the container in the relationship.

.PARAMETER Depth
Optional. The depth of memberships to retrieve when ContainerDescriptor is not specified. Default is 1.

.PARAMETER Direction
Optional. The direction of memberships to retrieve when ContainerDescriptor is not specified.

The default value for direction is 'up' meaning return all memberships where the subject is a member (e.g. all groups the subject is a member of).
Alternatively, passing the direction as 'down' will return all memberships where the subject is a container (e.g. all members of the subject group).

.PARAMETER Version
Optional. The API version to use for the request. Default is '7.1'.
Optional. The API version to use for the request. Default is '7.1-preview.1'.

.OUTPUTS
PSCustomObject

.LINK
https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/memberships/get
- https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/memberships/get
- https://learn.microsoft.com/en-us/rest/api/azure/devops/graph/memberships/list

.EXAMPLE
$params = @{
Expand All @@ -42,6 +53,28 @@
@('aadgp.00000000-0000-0000-0000-000000000002', 'aadgp.00000000-0000-0000-0000-000000000003') | Get-AdoMembership @params

Retrieves the membership relationships for multiple subjects demonstrating pipeline input.

.EXAMPLE
$params = @{
CollectionUri = 'https://vssps.dev.azure.com/my-org'
SubjectDescriptor = 'aadgp.00000000-0000-0000-0000-000000000000'
Depth = 2
Direction = 'up'
}
Get-AdoMembership @params

Retrieves all groups for a user with a depth of 2.

.EXAMPLE
$params = @{
CollectionUri = 'https://vssps.dev.azure.com/my-org'
SubjectDescriptor = 'aadgp.00000000-0000-0000-0000-000000000000'
Depth = 2
Direction = 'down'
}
Get-AdoMembership @params

Retrieves all memberships of a group with a depth of 2.
#>
[CmdletBinding()]
param (
Expand All @@ -52,9 +85,16 @@
[Parameter(Mandatory, ValueFromPipelineByPropertyName, ValueFromPipeline)]
[string[]]$SubjectDescriptor,

[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'GetMembership')]
[string]$ContainerDescriptor,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'ListMemberships')]
[int32]$Depth,

[Parameter(ValueFromPipelineByPropertyName, ParameterSetName = 'ListMemberships')]
[ValidateSet('up', 'down')]
[string]$Direction,

[Parameter()]
[Alias('ApiVersion')]
[ValidateSet('7.1-preview.1', '7.2-preview.1')]
Expand All @@ -66,6 +106,8 @@
Write-Debug ("CollectionUri: $CollectionUri")
Write-Debug ("SubjectDescriptor: $($SubjectDescriptor -join ',')")
Write-Debug ("ContainerDescriptor: $ContainerDescriptor")
Write-Debug ("Depth: $Depth")
Write-Debug ("Direction: $Direction")
Write-Debug ("Version: $Version")

Confirm-Default -Defaults ([ordered]@{
Expand All @@ -79,18 +121,38 @@

process {
try {
$queryParameters = [List[string]]::new()

if ($ContainerDescriptor) {
$uri = "$CollectionUri/_apis/graph/memberships/$SubjectDescriptor/$ContainerDescriptor"
} else {
$uri = "$CollectionUri/_apis/graph/memberships/$SubjectDescriptor"

if ($Depth) {
$queryParameters.Add("depth=$Depth")
}
if ($Direction) {
$queryParameters.Add("direction=$Direction")
}
}

$params = @{
Uri = "$CollectionUri/_apis/graph/memberships/$SubjectDescriptor/$ContainerDescriptor"
Version = $Version
Method = 'GET'
Uri = $uri
Version = $Version
QueryParameters = if ($queryParameters.Count -gt 0) { $queryParameters -join '&' } else { $null }
Method = 'GET'
}

$result = Invoke-AdoRestMethod @params
$results = Invoke-AdoRestMethod @params
$memberships = if ($ContainerDescriptor) { @($results) } else { $results.value }

[PSCustomObject]@{
memberDescriptor = $result.memberDescriptor
containerDescriptor = $result.containerDescriptor
collectionUri = $CollectionUri
foreach ($m_ in $memberships) {
$obj = [ordered]@{
containerDescriptor = $m_.containerDescriptor
memberDescriptor = $m_.memberDescriptor
collectionUri = $CollectionUri
}
[PSCustomObject]$obj
}

} catch {
Expand Down
Loading