Export user data to a form

Богдан Семенов 1 Reputation point
2021-06-01T12:28:16.847+00:00

Hello,

Is it possible to export user data from Azure AD (Name, Last name, etc.) into a form with a picture, that can be printed later?

Microsoft Security Microsoft Entra Microsoft Entra External ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Saurabh Sharma 23,846 Reputation points Microsoft Employee Moderator
    2021-06-01T19:38:06.357+00:00

    @Богдан Семенов Thanks for using Microsoft Q&A !!

    No, unfortunately, there is no direct API which you can use to fetch user information with photos you can however use Microsoft Graph to achieve your desired results.
    So, first you need to use Microsoft Graph to fetch Azure AD users using List Users endpoint which will give you Name, Last name and other attributes, then for each each individual users you need to use Get photo endpoint to get photo information, which will give you binary data of the requested photo.

    Microsoft Graph SDK will help you further simplify this approach which is currently available for languages and platforms as listed over here.
    Example code using Microsoft Graph SDK to get user properties -

    //Get users  
    var users = await graphClient.Users  
         .Request()  
         .Select(e => new  
                    {  
                        e.GivenName,  
                        e.Surname,  
                        e.DisplayName,  
                        e.UserPrincipalName                    
                    })  
          .GetAsync();  
    

    Also, sample code to get photo of specific user is as follows -

    var graphClient = new GraphServiceClient(  
                        new DelegateAuthenticationProvider(  
                            async (requestMessage) =>  
                            {  
                                requestMessage.Headers.Authorization =  
                                    new AuthenticationHeaderValue("Bearer", accessToken);  
                            }));  
          
                    byte[] bytePhoto;  
     // Get user photo  
    using (var pStream = await graphClient.Me.Photo.Content.Request().GetAsync())  
                    {  
                        bytePhoto = ((MemoryStream)pStream).ToArray();  
                          
                    }  
    var b64Photo = Convert.ToBase64String(photoByte);   
    

    Please check this discussion as a reference for getting user photo using Microsoft Graph.

    Also, if you want use "Bulk export" feature from Azure portal to export users details (without photo) as a CSV file.
    101428-image.png

    Please let me know if you have any other questions.

    ----------

    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.