View user accounts with Office 365 PowerShell

Summary: View your user accounts in various ways with Office 365 PowerShell.

Although you can use the Office 365 Admin center to view the accounts for your Office 365 tenant, you can also use Office 365 PowerShell and do some things that the Office 365 Admin center cannot.

Before you begin

The procedures in this topic require you to connect to Office 365 PowerShell. For instructions, see Connect to Office 365 PowerShell.

Display Office 365 user account information with Azure Active Directory PowerShell for Graph

The following sections describe how to display user account information.

All accounts

To display the full list of user accounts, run this command:

Get-AzureADUser

You should see information similar to this:

ObjectId                             DisplayName                                           UserPrincipalName
--------                             -----------                                           -----------------
032fc1fc-b5a2-46f1-8635-3d7dcb52c48d Adele Vance                                           AdeleV@litwareinc.OnMicr...
bd1e6af1-41e7-4f77-a2ac-5b209950135c Global Administrator                                  admin@litwareinc.onmicro...
ec37a4d6-232e-4eb7-82a5-1613490642a5 Alex Wilber                                           AlexW@litwareinc.OnMicro...
be4bdddd-c790-424c-9f96-a0cf609b7815 Allan Deyoung                                         AllanD@litwareinc.OnMicr...
598ab87b-76f0-4bf9-9538-bd46b10f4438 Christie Cline                                        ChristieC@litwareinc.OnM...
40722671-e520-4a5f-97d4-0bc9e9b2dc0f Debra Berger                                          DebraB@litwareinc.OnMicr...

A specific account

To display a specific user account, fill in the user principal name (UPN) of the user account, remove the "<" and ">" characters, and run this command:

Get-AzureADUser -ObjectID <UPN of user account>

Additional property values for a specific account

By default, the Get-AzureADUser cmdlet only displays the ObjectID, DisplayName, and UserPrincipalName properties of accounts.

To be more selective about the list of properties to display, you can use the Select-Object cmdlet in combination with the Get-AzureADUser cmdlet. To combine the two cmdlets, we use the "pipe" character "|", which tells Azure Active Directory PowerShell for Graph to take the results of one command and send it to the next command. Here is an example command that displays the DisplayName, Department, and UsageLocation for every user account:

Get-AzureADUser | Select-Object DisplayName,Department,UsageLocation

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts ( Get-AzureADUser ) and send it to the next command ( | ).

  • Display only the user account name, department, and usage location ( Select-Object DisplayName, Department, UsageLocation ).

To see all of the properties for user accounts, use the Select-Object cmdlet and the wildcard character (*) to display them all for a specific user account. Here is an example:

Get-AzureADUser -ObjectID "BelindaN@litwareinc.onmicosoft.com" | Select-Object *

As another example, you can check the enabled status of a specific user account with the following command:

Get-AzureADUser -ObjectID <UPN of user account> | Select-Object DisplayName,UserPrincipalName,AccountEnabled

Some accounts based on a common property

To be more selective about the list of accounts to display, you can use the Where-Object cmdlet in combination with the Get-AzureADUser cmdlet. To combine the two cmdlets, we use the "pipe" character "|", which tells Azure Active Directory PowerShell for Graph to take the results of one command and send it to the next command. Here is an example command that displays only those user accounts that have an unspecified usage location:

Get-AzureADUser | Where-Object {$_.UsageLocation -eq $Null}

This command instructs Azure Active Directory PowerShell for Graph to:

  • Get all of the information on the user accounts ( Get-AzureADUser ) and send it to the next command ( | ).

  • Find all of the user accounts that have an unspecified usage location ( Where-Object {$_.UsageLocation -eq $Null} ). Inside the braces, the command instructs Office 365 PowerShell to only find the set of accounts in which the UsageLocation user account property ( $_.UsageLocation ) is not specified ( -eq $Null ).

The UsageLocation property is only one of many properties associated with a user account. To see all of the properties for user accounts, use the Select-Object cmdlet and the wildcard character (*) to display them all for a specific user account. Here is an example:

Get-AzureADUser -ObjectID "BelindaN@litwareinc.onmicosoft.com" | Select-Object *

For example, from this list, City is the name of a user account property. This means you can use the following command to list all of the user accounts for users living in London:

Get-AzureADUser | Where-Object {$_.City -eq "London"}

Tip

The syntax for the Where-Object cmdlet shown in these examples is Where-Object {$_. [user account property name] [comparison operator] [value] }.> [comparison operator] is -eq for equals, -ne for not equals, -lt for less than, -gt for greater than, and others. [value] is typically a string (a sequence of letters, numbers, and other characters), a numerical value, or $Null for unspecified> See Where-Object for more information.

Display Office 365 user account information with Microsoft Azure Active Directory Module for Windows PowerShell

The following sections describe how to display user account information.

All accounts

To display the full list of user accounts, run this command:

Get-MsolUser

You should see information similar to this:

UserPrincipalName                     DisplayName           isLicensed
-----------------                     -----------           ----------
ZrinkaM@litwareinc.onmicrosoft.com    Zrinka Makovac        True
BonnieK@litwareinc.onmicrosoft.com    Bonnie Kearney        True
FabriceC@litwareinc.onmicrosoft.com   Fabrice Canel         True
BrianJ@litwareinc.onmicrosoft.com     Brian Johnson         False 
AnneWlitwareinc.onmicrosoft.com       Anne Wallace          True
ScottW@litwareinc.onmicrosoft.com     Scott Wallace         False

The Get-MsolUser cmdlet also has a set of parameters to filter the set of user accounts displayed. For example, for the list of unlicensed users (users who've been added to Office 365 but haven't yet been licensed to use any of the services), run this command.

Get-MsolUser -UnlicensedUsersOnly

You should see information similar to this:

UserPrincipalName                     DisplayName           isLicensed
-----------------                     -----------           ----------
BrianJ@litwareinc.onmicrosoft.com     Brian Johnson         False
ScottW@litwareinc.onmicrosoft.com     Scott Wallace         False

For more information about additional parameters to filter the display the set of user accounts displayed, see Get-MsolUser.

A specific account

To display a specific user account, fill in the user principal name (UPN) of the user account, remove the "<" and ">" characters, and run this command:

Get-MsolUser -UserPrincipalName <UPN of user account>

Some accounts based on a common property

To be more selective about the list of accounts to display, you can use the Where-Object cmdlet in combination with the Get-MsolUser cmdlet. To combine the two cmdlets, we use the "pipe" character "|", which tells Office 365 PowerShell to take the results of one command and send it to the next command. Here is an example command that displays only those user accounts that have an unspecified usage location:

Get-MsolUser | Where-Object {$_.UsageLocation -eq $Null}

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts ( Get-MsolUser ) and send it to the next command ( | ).

  • Find all of the user accounts that have an unspecified usage location ( Where-Object {$_.UsageLocation -eq $Null} ). Inside the braces, the command instructs Office 365 PowerShell to only find the set of accounts in which the UsageLocation user account property ( $_.UsageLocation ) is not specified ( -eq $Null ).

You should see information similar to this:

UserPrincipalName                     DisplayName           isLicensed
-----------------                     -----------           ----------
BrianJ@litwareinc.onmicrosoft.com     Brian Johnson         False 
ScottW@litwareinc.onmicrosoft.com     Scott Wallace         False

The UsageLocation property is only one of many properties associated with a user account. To see all of the properties for user accounts, use the Select-Object cmdlet and the wildcard character (*) to display them all for a specific user account. Here is an example:

Get-MsolUser -UserPrincipalName "BelindaN@litwareinc.onmicosoft.com" | Select-Object *

For example, from this list, City is the name of a user account property. This means you can use the following command to list all of the user accounts for users living in London:

Get-MsolUser | Where-Object {$_.City -eq "London"}

Tip

The syntax for the Where-Object cmdlet shown in these examples is Where-Object {$_. [user account property name] [comparison operator] [value] }. [comparison operator] is -eq for equals, -ne for not equals, -lt for less than, -gt for greater than, and others. [value] is typically a string (a sequence of letters, numbers, and other characters), a numerical value, or $Null for unspecified. See Where-Object for more information.

You can check the blocked status of a user account with the following command:

Get-MolUser -UserPrincipalName <UPN of user account> | Select-Object DisplayName,BlockCredential

Additional property values for accounts

The Get-MsolUser cmdlet by default displays three properties of user accounts:

  • UserPrincipalName

  • DisplayName

  • isLicensed

If you need additional properties, such as the department the user works for and the country/region where the user uses Office 365 services, you can run Get-MsolUser in combination with the Select-Object cmdlet to specify the list of user account properties. Here is an example:

Get-MsolUser | Select-Object DisplayName, Department, UsageLocation

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts ( Get-MsolUser ) and send it to the next command ( | ).

  • Display only the user account name, department, and usage location ( Select-Object DisplayName, Department, UsageLocation ).

You should see information similar to this:

DisplayName             Department                       UsageLocation
-----------             ----------                       -------------
Zrinka Makovac          Sales & Marketing                    US
Bonnie Kearney          Sales & Marketing                    US
Fabrice Canel           Legal                                US
Brian Johnson
Anne Wallace            Executive Management                 US
Alex Darrow             Sales & Marketing                    US
Scott Wallace           Operations

The Select-Object cmdlet lets you pick and choose the properties you want a command to display. To see all of the properties for user accounts, use the wildcard character (*) to display them all for a specific user account. Here is an example:

Get-MsolUser -UserPrincipalName "BelindaN@litwareinc.onmicosoft.com" | Select-Object *

To be more selective about the list of accounts to display, you can also use the Where-Object cmdlet. Here is an example command that displays only those user accounts that have an unspecified usage location:

Get-MsolUser | Where-Object {$_.UsageLocation -eq $Null} | Select-Object DisplayName, Department, UsageLocation

This command instructs Office 365 PowerShell to:

  • Get all of the information on the user accounts ( Get-MsolUser ) and send it to the next command ( | ).

  • Find all of the user accounts that have an unspecified usage location ( Where-Object {$_.UsageLocation -eq $Null} ) and send the resulting information to the next command ( | ). Inside the braces, the command is instructing Office 365 PowerShell to only find the set of accounts in which the UsageLocation user account property ( $_.UsageLocation ) is not specified ( -eq $Null ).

  • Display only the user account name, department, and usage location ( Select-Object DisplayName, Department, UsageLocation ).

You should see information similar to this:

DisplayName              Department                      UsageLocation
-----------              ----------                      -------------
Brian Johnson 
Scott Wallace            Operations

If you are using directory synchronization to create and manage your Office 365 users, you can display which local account an Office 365 user has been projected from. The following assumes that Azure AD Connect has been configured to use the default source anchor of ObjectGUID (for more on configuring a source anchor, see Azure AD Connect: Design concepts) and assumes that the Active Directory module for powershell has been installed (see RSAT tools):

(Get-ADUser [guid][system.convert]::frombase64string((Get-MsolUser -UserPrincipalName <UPN of user account>).ImmutableID)).Guid

New to Office 365?

Tip

LinkedIn logo New to Office 365?

Discover free video courses for Office 365 admins and IT pros, brought to you by LinkedIn Learning.

See also

Manage user accounts and licenses with Office 365 PowerShell

Manage Office 365 with Office 365 PowerShell

Getting started with Office 365 PowerShell