Get own Service Principal Name in an Azure DevOps Powershell pipeline task Get own Service Principal Name in an Azure DevOps Powershell pipeline task azure azure

Get own Service Principal Name in an Azure DevOps Powershell pipeline task


Information about the Service Principal can be accessed using Get-AzureRmContext but the information is limited and some is obfuscated in the logs so you need to make a second call to Get-AzureRmServicePrincipal to access the ObjectId

$Context = Get-AzureRmContext$AzureDevOpsServicePrincipal = Get-AzureRmADServicePrincipal -ApplicationId $Context.Account.Id$ObjectId = $AzureDevOpsServicePrincipal.Id

The Id exposed in $Context.Account.Id is the Service Principals ApplicationId


SPN within a pipeline task is nothing but the Azure subscription you have passed on to the task. You can click on manage connections and copy the details of the SPN under connections and use them as you need. But, I am not sure why do you want to use the SPN directly as you can always use an Azure Powershell Task and just select the subscription. Once you store the Connection, you can always reuse it in different pipelines.

enter image description here