Viewing Office 365 User Account Details Using Get-MsolUser

In this article we’ll show you how to get a various information about Office 365 user accounts using the Get-MsolUser PowerShell cmdlet. The Get-MsolUser cmdlet allows you to view the properties of one or several Office 365 accounts. This is an analog of the Get-ADUser cmdlet for on-premises Active Directory. The Get-MsolUser cmdlet is part of the Azure AD PowerShell module (MSOnline). It allows you to connect to your Office 365 subscription. Thus, to use this cmdlet you must first download and install this module. You can download and install the MSOnline manually (exe/msi installer), or install it online from the PowerShell Gallery. To do this, just run the command in the PoSh console:

Find-Module -Name MSOnline | Install-Module -Force


To connect to an Office 365 subscription, save your credentials to a variable:

$MSOCred = Get-Credential

In the window that appears, enter the account’s credentials with the permissions to connect to your Office 365 tenant.

get-msoluser all properties

Now connect to your subscription with saved credentials:

Connect-MsolService -Credential $MSOCred

After connecting, run the command:


This command will return a list of all Office 365 users. By default, the UPN, Display name, and the isLicensed attributes are returned.

get-msoluser all attributes

To display information about a specific user, you can specify its UserPrincipalName. You can display all user attributes:

Get-MsolUser -UserPrincipalName "”| Select-Object *|Format-List

get-msoluser where-object

The user account contains a number of attributes that determine their properties, parameters, and personal info (phone number, department, company, etc.). You can only request for a specific attributes:

Get-MsolUser -UserPrincipalName “” | Select-Object UserPrincipalName, DisplayName, Department, UsageLocation

You can export this list to a CSV file (convenient for opening in Excel):

Get-MsolUser | Select-Object UserPrincipalName, DisplayName, PhoneNumber, Department, UsageLocation| Export-CSV c:\ps\o365userlist.csv –NoTypeInformation

Below are some useful queries for getting data about Office 365 users with the help of the Get-MsolUser cmdlet.

You can display all users of a specific department:

Get-msoluser | Where {$_.Department -eq “Sales Dept”}

Let’s display the list of users and licenses assigned to them:

Get-MsolUser | Where-Object {$_.isLicensed -like "True"} | FT DisplayName, licenses, islicensed

List of assigned license options:

(Get-MsolUser –UserPrincipalName ).Licenses[0].ServiceStatus

List of users without a license:

Get-MsolUser –UnlicensedUsersOnly

List of deleted account (useful if you accidentally deleted an Office 365 account, when you urgently need to restore it):

Get-MsolUser -ReturnDeletedUsers | FL UserPrincipalName,ObjectID

List the time of the last password change for Office 365 users:

Get-MsolUser -All | select DisplayName, LastPasswordChangeTimeStamp

List the active (enabled) accounts:

Get-MsolUser -EnabledFilter EnabledOnly -ALL

List the disabled accounts:

Get-MsolUser -EnabledFilter DisabledOnly -ALL

Display a list of users who haven’t changed their passwords for more than 90 days:

Get-MsolUser | Where-Object { $.LastPasswordChangeTimestamp -lt (Get-Date).AddDays(-90)} | Select-Object DisplayName,UserPrincipalName,LastPasswordChangeTimestamp,Licenses,PasswordNeverExpires | Format-Table
I enjoy technology and developing websites. Since 2012 I'm running a few of my own websites, and share useful content on gadgets, PC administration and website promotion.
Cyril Kardashevsky

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.