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