Home ยป Office 365 ยป Get-MsolUser – Get All Msol Users in PowerShell

Get-MsolUser – Get All Msol Users in PowerShell

The Get-MsolUser cmdlet in PowerShell gets an individual user or list of users from the Azure Active Directory. The Get-MsolUser command gets all user properties such as DisplayName, IsLicensed, UserPrincipalName, etcโ€ฆ

The syntax to get a list of users in Office 365 is given below.

Get-MsolUser

This command returns all users from the Office 365 or Azure Active Directory.

Get-MsolUser - list all users from Azure AD
Get-MsolUser โ€“ list all users from Azure AD

In this article, we will discuss how to use the Get-MsolUser cmdlet in PowerShell to get a list of users in Azure AD, get enabled users, get a user by userprinciplaname, get users by search string, get a licensed users list, and get an unlicensed users list.

How to Get All Users in Office 365 in PowerShell

To get all users in Office 365 or Azure Active Directory, use the Get-MsolUser cmdlet.

Get-MsolUser

This command retrieves all users in the organization. It displays up to the default value of 500 results.

To get more than 500 users in an Office 365, use the Get-MsolUser command with -All or -MaxResults parameters.

# Retrieves more than 500 users in the company
Get-MsolUser -All

# Specify maximum result to retrieve number of users in the company
Get-MsolUser -MaxResults 2000

How to Show All Properties for MsolUser

Use the Get-MsolUser cmdlet in PowerShell to show all properties of the user in Microsoft Office 365. This command uses the UserPrincipalName parameter to retrieve user objects from Azure Active Directory.

Get-MsolUser -UserPrincipalName "[email protected]" | FL

In the above PowerShell script, the Get-MsolUser cmdlet retrieves the user object โ€œ[email protected]โ€ and uses the Format-List cmdlet to format the output of the Get-MsolUser cmdlet and display all of the properties of the user.

The output of the above PowerShell script shows all properties of the Msol user in Office 365.

Get-MsolUser - Show All Properties of a User in Office 365
Get-MsolUser โ€“ Show All Properties of a User in Office 365

How to Get Enabled Users in Office 365 in PowerShell

To get enabled users in Office 365 in PowerShell, use the Get-MsolUser command with the EnabledFilter parameter to check only EnabledOnly users in the company.

Get-MsolUser -EnabledFilter EnabledOnly -MaxResults 1000

In the above PowerShell script, the Get-MsolUser cmdlet in PowerShell uses the EnabledFilter parameter to filter EnabledOnly users in the company. The command uses the MaxResults parameter to get up to 1000 enabled users.

How to Get a User by UserPrincipalName in Office 365 Using PowerShell

To get a user by UserPrincipalName in Office 365, use the Get-MsolUser cmdlet with the UserPrincipalName parameter.

Get-MsolUser -UserPrincipalName "[email protected]" 

In the above PowerShell script, the Get-MsolUser cmdlet uses the UserPrincipalName parameter to specify the user principalname โ€œ[email protected]โ€ and retrieves detailed information about a user in Office 365.

The output of the above PowerShell script to find a user by userprincipalname is given below.

Get a User by UserPrincipalName in Office 365
Get a User by UserPrincipalName in Office 365

How to Search User by Search String in Azure Active Directory

To search users by search string in Azure Active Directory, use the Get-MsolUser cmdlet in PowerShell with the SearchString parameter.

The SearchString parameter specifies a string to match the email address or display name starting with this string.

Get-MsolUser -SearchString "samer"

In the above PowerShell script, the Get-MsolUser command retrieves a list of users with โ€œsamerโ€ in the display name or email address.

The output of the above PowerShell script to get users by search string is given below.

PS C:\WINDOWS\system32> Get-MsolUser -SearchString "samer"                                                              
UserPrincipalName                  DisplayName    isLicensed
-----------------                  -----------    ----------
[email protected] samer amberson True


PS C:\WINDOWS\system32>  

How to Get a User by Object ID

Use the Get-MsolUser cmdlet in PowerShell with the ObjectId parameter to specify the object ID of a user to get a user by object ID.

Get-MsolUser -ObjectId 1f149c47-a670-4f12-a4ac-01423cbafb58 

This command retrieves a user that has the specified object ID.

The output of the above PowerShell script to find a user by Object ID is given below.

PS C:\WINDOWS\system32> Get-MsolUser -ObjectId 1f149c47-a670-4f12-a4ac-01423cbafb58                                     
UserPrincipalName                 DisplayName isLicensed
-----------------                 ----------- ----------
[email protected] gary edler  False


PS C:\WINDOWS\system32>        

Conclusion

I hope the above article on how to use the Get-MsolUser cmdlet in PowerShell to get all users in Office 365 and show all properties of a user is helpful to you.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.