Skip to content

Instantly share code, notes, and snippets.

@pcdoyle
Created November 17, 2022 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcdoyle/12db8e275f4e668281fbfc031472c677 to your computer and use it in GitHub Desktop.
Save pcdoyle/12db8e275f4e668281fbfc031472c677 to your computer and use it in GitHub Desktop.
This command will get the Azure AD User by their UPN's domain.
Get-AzureADUser -All $true | `
where-object {($_.UserPrincipalName -like "*@example.com") -and ($_.AccountEnabled -eq $true)} | `
Select-Object -property UserPrincipalName,DisplayName,AccountEnabled | `
Export-Csv -Path .\ActiveERISUsers.csv
@pcdoyle
Copy link
Author

pcdoyle commented Nov 17, 2022

You can add multiple domains by adding an -or to the second line:

where-object {($_.UserPrincipalName -like "*@example.com") -or ($_.UserPrincipalName -like "*@other.example.com") -and ($_.AccountEnabled -eq $true)}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment