Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Powershell to extract AAD user info based on a list of AAD user IDs.
This script imports a list of UPN's and extracts more user information from Azure Active Directory via the AzureAD PS module.
$upns = import-csv "C:\Directory\File.csv" # Replace filepath here
Connect-AzureAD ##Login interactively
$ad_info = @()
foreach ($upn in $upns){
## Change $upn.UserId to whatever the column header for UPN is (e.g. $upn.UPN or $
$ad_info += Get-AzureADUser -Filter "userPrincipalName eq '$($upn.UserId)'" | Select-Object userPrincipalName, displayName, jobTitle
$usx | Export-Csv -NoTypeInformation -Path "C:\Directory\File.csv" #Export to CSV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment