View Properties of Office 365 User Account Using Powershell

We’ve seen previously how to view the properties of a user account in active directory, this time we’re going to take a look at viewing the properties of a user in Office 365.

The GUI account properties screen of a user account in office 365 is quite limited, by using the below Powershell commands you’ll be able to view a lot more.

Connect to Offer 365 and Create a Session

You need to connect to Office 365 and start a session before you can start interacting with the environment using Powershell. Here is the code to start the session, you will be prompted for your admin account details.

Open up Powershell ISE and run the below command:

$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Once you have finished doing what you need to do, make sure you always end your session by running the below Powershell command:

Remove-PSSession $Session

Return All Account Details

Lets now run the below command to retrieve the account details of a specified user.

Connect-MsolService
GET-MSOLUSER -userprincipalname "Account name" | SELECT *

As the user principal name is unique on each account, it makes it a good field to search by. You will then seen the properties of the account displayed, similar to below:

Office 365 Powershell

Return Specific Details

The below code is exactly like the above command, but it specifies an exact field to display. So if you know what you are looking for you don’t have to trawl through all the properties.

Connect-MsolService
GET-MSOLUSER -userprincipalname "Account name" | SELECT DisplayName

This will just return the display name of the account and nothing more

Leave a Reply

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