How to Get List of Azure Active Directory Users Using PowerShell
Problem
In this blog post, we will walk you through how to get list of Azure Active Directory (Azure AD) users using PowerShell.
Solution
As of this writing, there are two PowerShell modules that can be used to get Azure AD users.
Az
module
In this module, we can useGet-AzADUser
cmdlet.AzureAD
module
In this module, we can useGet-AzureADUser
cmdlet.
It is possible that in the future one of the module will be merged to the other module.
This article requires us to install and connect to appropriate Azure AD tenant first. For complete detail, you can read article how to switch Azure Active Directory tenant.
Using Get-AzADUser cmdlet
To use this command, we must have installed Az
module. Then, we connect to our Azure AD tenant or directory.
Install-Module Az
Connect-AzAccount
After connect to Azure AD, we can list all available tenants to get TenantId
and choose one of them to switch.
Get-AzTenant
Set-AzContext -TenantId bc1c4faa-ed08-429b-a99e-bf30696f78f2
For more detail regarding switching tenant, you can read article how to switch Azure Active Directory tenant.
Anyway, as the last step, we can get list of Azure AD users as follows:
Get-AzADUser
The result will look as follows:
Using Get-AzureADUser cmdlet
To use this command, we must have installed AzureAD
module. Then, we connect to our Azure AD tenant or directory.
For more detail regarding switching tenant, you can read article how to switch Azure Active Directory tenant.
Example below specifies TenantId
that we get from previous solution because AzureAD
module does not have command to list all available tenants.
Install-Module AzureAD
Connect-AzureAD -TenantId bc1c4faa-ed08-429b-a99e-bf30696f78f2
After connect to Azure AD, we can execute Get-AzureADUser
cmdlet to get list of Azure AD users in current tenant or directory.
Get-AzureADUser
The result will look as follows:
Conclusion
In order to get list of Azure AD users, we can use Get-AzADUser
or Get-AzureADUser
cmdlet. These cmdlets resides in different module, so we cannot combine them unless we have connected to both of them using Connect-AzAccount
or Connect-AzureAD
cmdlet.
In case we have multiple tenants, we should switch to correct tenant or directory first before getting the list of Azure AD users.