Search CSV for matching Azure AD accounts

I needed to search our Azure AD for who of the usernames contained in a CSV were real ID and who were not.

This is how I did it.

First of all you need to installed the Azure Active Directory module in Powershell, make sure you launch as a Administrator

Install-Module -Name AzureAD

Connect-AzureAD

Then

$data = Import-Csv ‘C:\Users\OneDrive\ids.csv’

$data | ForEach-Object {
Get-AzureADUser -ObjectId $_.UserPrincipalName | Select-Object DisplayName,UserPrincipalName,Department | Export-csv -append -notypeinformation “C:\Users\OneDrive\names.csv”
}

In the ids.csv I have a list with the header of ‘UserPrincipalName’

Run the above one part at a time and it’ll write DisplayName,UserPrincipalName,Department into the names.csv

When I get chance I’ll change the above to show a username does not exist entry if that is the case, current it just tells you this in the powershell window.

One comment

  1. Pingback: Advanced Mail Merge : Multiple clickable URL entries per mail to user | Not so many...

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s