Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Powershell to extract AAD user info based on a list of AAD user IDs.
<#
.DESCRIPTION
This script imports a list of UPN's and extracts more user information from Azure Active Directory via the AzureAD PS module.
.LINK
https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureaduser?view=azureadps-2.0
#>
$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 $upn.email)
$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