user6264
user6264

Reputation: 185

How to get Azure Active Directory user details from pipeline?

I have a requirement to create a key vault in Azure using a power shell. This PS script runs from the pipeline.

$UserObjectId = (Get-AzureRmADUser -SearchString xxxxxxxxxx).Id

I used the above command to get user id but I got the error as

"Insufficient privileges to complete this operation". Do I need to give any permission to the user from which the pipeline executing?

Upvotes: 1

Views: 1528

Answers (1)

Mohit Verma
Mohit Verma

Reputation: 5296

Yes absolutely , you have to provide permission to the user under you pipeline is running. User should be having Directory.RaadAll, Read All User basic profile permission to read thorugh their profile.

But Ideally you should be running your Azure Devops pipeline using Service Principal and you should provide the permission to your application.

You can refer this link for creating app identity(Service Principal)

https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal

Then you can login to the Azure portal and browse through the application and provide the permission under Windows Azure Directory like below:

enter image description here:

Check this for further reference:

https://blog.hqcodeshop.fi/archives/435-Setting-up-Azure-AD-Application-from-Azure-DevOps-pipeline-Powershell-task,-Part-2-of-2-The-scripts.html

Hope it helps.

Upvotes: 1

Related Questions