azure-devopsactive-directoryaccount-management

Remove Azure DevOps Account when remove from company AD


Is there a automatic(script or similar) way of removing account subscription from Azure DevOps when account removed from company AD. Today this is a manual effort in our company and not very effective.


Solution

  • If you want to delete service connections of subscriptions, you can use some REST APIs.

    Step1. Get the project id where you want to delete connections

    GET https://dev.azure.com/{organization}/_apis/projects/{projectName}?api-version=6.1-preview.4
    

    Step2. Get a list of service connection ids in the project:Endpoints - Get Service Endpoints list

    GET https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=6.1-preview.4
    

    Or you can get a specific service connection id by its name: Endpoints - Get Service Endpoints By Names:

    GET https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?endpointNames={endpointNames}&api-version=6.1-preview.4
    

    Step3: Delete service connections: Endpoints - Delete:

    DELETE https://dev.azure.com/{organization}/_apis/serviceendpoint/endpoints/{endpointId}?projectIds={projectIds}&api-version=6.1-preview.4
    

    Multiple service connections can be quickly deleted by using the service connection id as the {endpointId} and repeating this REST API.