11<#
22. SYNOPSIS
3- Returns all service connections / service endpoints of an Azure DevOps organization
3+ Returns all service connections / service endpoints of an Azure DevOps organization
4+
45. DESCRIPTION
5- An Azure DevOps automation script that returns all service connections / service endpoints of an Azure DevOps organization
6+ An Azure DevOps automation script that returns all service connections / service endpoints of an Azure DevOps organization
7+
68. PARAMETER PersonalAccessToken
7- Azure DevOps personal access token (PAT) with the following scopes: User Profile (Read), Project and Team (Read), Service Connections (Read & query)
9+ Azure DevOps personal access token (PAT) with the following scopes: User Profile (Read), Project and Team (Read), Service Connections (Read & query)
10+
811. PARAMETER OrganizationName
9- Name of the Azure DevOps organization
12+ Name of the Azure DevOps organization
13+
1014. PARAMETER PrintToConsole
11- If set to true, the output will be printed to the console
15+ If set to true, the output will be printed to the console
16+
1217. INPUTS
13- None
18+ None
19+
1420. OUTPUTS
15- The service connections / service endpoints of the given Azure DevOps organization
21+ The service connections / service endpoints of the given Azure DevOps organization
22+
1623. NOTES
17- Version: 1.0
18- Author: Marc Rufer
19- Creation Date: 01.01.2024
20- Purpose/Change: Initial script development
24+ Version: 1.0
25+ Author: Marc Rufer
26+ Creation Date: 01.01.2024
27+ Purpose/Change: Initial script development
28+
2129. EXAMPLE
22- Retrieve service connections without printing to console
23- .\Get-ServiceConnections.ps1 -PersonalAccessToken "your_personal_access_token" -OrganizationName "your_organization_name"
30+ PS> .\Get-ServiceConnections.ps1 -PersonalAccessToken "PAT_HERE" -OrganizationName "ORGANIZATION_NAME_HERE"
31+
2432. EXAMPLE
25- Retrieve service connections and print to console
26- .\Get-ServiceConnections.ps1 -PersonalAccessToken "your_personal_access_token" -OrganizationName "your_organization_name" -PrintToConsole
33+ PS> .\Get-ServiceConnections.ps1 -PersonalAccessToken "PAT_HERE" -OrganizationName "ORGANIZATION_NAME_HERE" -PrintToConsole
2734#>
2835PARAM
2936(
30- [Parameter (Mandatory = $true , Position = 0 , HelpMessage = " Azure DevOps personal access token (PAT) with scopes: User Profile (Read), Project and Team (Read), Service Connections (Read & query)." )]
31- [string ] $PersonalAccessToken
32- ,
33- [Parameter (Mandatory = $true , Position = 1 )]
34- [string ] $OrganizationName
35- ,
36- [Parameter (Mandatory = $false , Position = 2 )]
37- [switch ] $PrintToConsole = $false
37+ [Parameter (Mandatory = $true , Position = 0 , HelpMessage = " Azure DevOps personal access token (PAT) with scopes: User Profile (Read), Project and Team (Read), Service Connections (Read & query)." )]
38+ [string ] $PersonalAccessToken
39+ ,
40+ [Parameter (Mandatory = $true , Position = 1 )]
41+ [string ] $OrganizationName
42+ ,
43+ [Parameter (Mandatory = $false , Position = 2 )]
44+ [switch ] $PrintToConsole = $false
3845)
3946
4047$base64encodedPAT = [Convert ]::ToBase64String([System.Text.Encoding ]::UTF8.GetBytes(" `:$PersonalAccessToken " ))
@@ -46,22 +53,22 @@ $projects = $response.value
4653$serviceConnections = [System.Collections.ArrayList ]::new()
4754
4855foreach ($project in $projects ) {
49- $uri = " https://dev.azure.com/{0}/{1}/_apis/serviceendpoint/endpoints?api-version=7.2-preview.4" -f $Organizationname , $project.name
50- $response = Invoke-RestMethod - Method Get - Uri $uri - Headers @ {' Authorization' = " Basic $base64encodedPAT " }
56+ $uri = " https://dev.azure.com/{0}/{1}/_apis/serviceendpoint/endpoints?api-version=7.2-preview.4" -f $Organizationname , $project.name
57+ $response = Invoke-RestMethod - Method Get - Uri $uri - Headers @ {' Authorization' = " Basic $base64encodedPAT " }
5158
52- $serviceEndpoints = $response.value
53- foreach ($serviceEndpoint in $serviceEndpoints ) {
54- $null = $serviceConnections.Add ($serviceEndpoint )
55- }
59+ $serviceEndpoints = $response.value
60+ foreach ($serviceEndpoint in $serviceEndpoints ) {
61+ $null = $serviceConnections.Add ($serviceEndpoint )
62+ }
5663}
5764
5865if ($PrintToConsole ) {
59- Write-Host " Azure DevOps organization: $OrganizationName " - ForegroundColor Green
60- Write-Host (" Projects count: {0}" -f $projects.Count ) - ForegroundColor Green
61- Write-Host (" Service connection count: {0}" -f $serviceConnections.Count ) - ForegroundColor Green
62- Write-Host " "
66+ Write-Host " Azure DevOps organization: $OrganizationName " - ForegroundColor Green
67+ Write-Host (" Projects count: {0}" -f $projects.Count ) - ForegroundColor Green
68+ Write-Host (" Service connection count: {0}" -f $serviceConnections.Count ) - ForegroundColor Green
69+ Write-Host " "
6370
64- $serviceConnections | Format-Table - AutoSize - Wrap - GroupBy isOutdated - Property name, type, @ {Name = " environment" ; Expression = {$_.data.environment }}, @ {Name = " scopeLevel" ; Expression = {$_.data.scopeLevel }}, @ {Name = " subscriptionName" ; Expression = {$_.data.subscriptionName }}, @ {Name = " authScheme" ; Expression = {$_.authorization.scheme }}, isShared, isReady
71+ $serviceConnections | Format-Table - AutoSize - Wrap - GroupBy isOutdated - Property name, type, @ {Name = " environment" ; Expression = {$_.data.environment }}, @ {Name = " scopeLevel" ; Expression = {$_.data.scopeLevel }}, @ {Name = " subscriptionName" ; Expression = {$_.data.subscriptionName }}, @ {Name = " authScheme" ; Expression = {$_.authorization.scheme }}, isShared, isReady
6572}
6673
6774return $serviceConnections
0 commit comments