question

54979432 avatar image
0 Votes"
54979432 asked SaurabhSharma-msft commented

Export user data to a form

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?

azure-ad-b2b
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

SaurabhSharma-msft avatar image
0 Votes"
SaurabhSharma-msft answered SaurabhSharma-msft commented

@54979432 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.



image.png (43.8 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @54979432,

I have not heard back from you. Did my answer solve your issue? If so, please mark as accepted answer. If not, please let me know how I may better assist.

Thanks
Saurabh

0 Votes 0 ·

Hi @54979432,

Please let me know if you find above reply useful. If yes, do click on 'Mark as answer' link in above reply. This will help other community members facing similar query to refer to this solution.

Thanks
Saurabh

0 Votes 0 ·