How can I export users UPN and E-mail from a list of csv and returning this values from Azure Entra ID users

Franthesco De Paula Ferrari 20 Reputation points
2023-12-21T18:33:51.14+00:00

Hello there!!

I need to export not all users but some from a csv list to obtain only UPN and Email fields from Azure Entra ID users. Is that possible??

Eg:.

csv input file:
User's image

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,813 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
23,263 questions
{count} votes

Accepted answer
  1. Akhilesh Vallamkonda 11,840 Reputation points Microsoft Vendor
    2023-12-28T06:39:47.9+00:00

    Hi @Franthesco De Paula Ferrari
    Greetings!
    Thank you for posting your query on Q&A.
    I understand that you are trying to Import a csv file with the some of existing user details in the tenant and you want to export the listed user details with the required filed such as Mail and Name, Email, Display name.
    To achieve your ask you can use the below power shell script.

    $users=@() 
    $csvFile = Import-Csv -Path "C:\Import\sampleuser_2.csv" 
    foreach ($row in $csvFile) {     
        $displayName = $row.displayName     
     	$users += Get-AzureADUser -Filter "DisplayName eq '$displayName'" | Select-Object UserPrincipalName,ObjectId,Mail  
    }
    $users | Export-Csv -Path "C:\Export\sampleuser_2.csv" -NoTypeInformation
    

    In the above script it will extract the UserPrinciplName, Mail, ObjectId from the given input.
    If you want to import more fields you can make the changes by adding the name of the fields in the 5th line of the above script.
    I hope this answer helps! please Feel free to ask any questions you may have.

    Thanks,
    Akhilesh.
    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 117.9K Reputation points MVP
    2023-12-21T19:24:42.4333333+00:00

    Hi @Franthesco De Paula Ferrari ,

    it's possible to search in Azure Entra ID for a list of users in an csv file and export the result with the required fields to another csv.

    Maybe this script helps to get started (modify the file names to your needs):

    Import-Csv -Path .\sampleuser_2.csv -Encoding UTF8 | ForEach-Object {
    	Get-AzureADUser -SearchString "$($_.name)" | Select-Object DisplayName, UserPrincipalName,Mail | Export-Csv -Path .\sampleuser_3.csv -Encoding UTF8 -Append -NoTypeInformation
    }
    
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    0 comments No comments

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.