Home > database >  Azure Devops > How to retrieve Service Connection information with powershell?
Azure Devops > How to retrieve Service Connection information with powershell?

Time:05-07

Good morning Azure expert,

I configured a service connexion with Azure cloud environment in my Azure DevOps server like below enter image description here

Then in my release I have a Powershell script which need to retrieve some information like TenantID/ SP id / SP secret / Subscription ID.

I do not want to create release variable to avoid duplication.

I'm pretty sure these variables could be retrieve with powershell but I have totally no idea on how to do it. Do you have any idea - suggestions - recommendation ?

Regards, Terry

CodePudding user response:

You can use the below script to get the service connection details which will use the RestAPI,

For example:

$token = "{pat}"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$url="https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?endpointNames={endpointNames}&api-version=6.0-preview.4"
$head = @{ Authorization =" Basic $token" }
Invoke-RestMethod -Uri $url -Method GET -Headers $head
  • SOURCE| SO THREAD as suggested by @Jane Ma-MSFT.

For more information please refer the below links:

  • Related