read email addresses from CSV and get company, department and jobtitle

Appreciate any help.

I have been provided with a list of internal email addresses and there’s too many to manually look up the company, department and jobtitle for each one.

How could I read in list and look up company, department and jobtitle for each one and export the results to a CSV?

I would have to repeat this every month.


Show your current code and I will help with your issue.

Fair comment. I don’t have code at the moment beyond using Get-AzureADUser to do it for one user. Prior to posting I’ve spent several hours googling for an answer or some clue about how to wrap the command in a ForEach loop. I’m not a PowerShell user and from what I read I probably need to use Get-ADUser and work out how to get that cmdlet , because I don’t have it.

What format is this list? csv? Can you provide at least a sample of what you are trying to import. Redact whatever you need, the actual data is unimportant but the format is needed to help.

Hi, it is a single column in a CSV.

Column heading

Output I’m being asked for is

email address | Company name | Department | Job Title

We use the company field for different parts of our org so it varies.

One of these fields will reveal if the user is one we need to speak to. They will either have a keyword we are interested in, or will work in an area where we know the type of work they do, similarly with job title. It’s essentially a reverse look up because the requests they are making to our service doesn’t capture where in our org they work.

I don’t have an Azure environment to test this, but try it.

$result = Get-Content -Path .\emailaddress.csv | ForEach-Object {
    Get-AzureADUser -ObjectId "$_" | Select-Object UserPrincipalName,

$result | Export-Csv -Path .\result.csv -NoTypeInformation

Holy moly! lightning quick and did exactly what I wanted. You’ve saved me a load of manual handling.