Press ESC to close

Retrieve users including names and country from Office 365

Today I had to retrieve all the Office 365 users, including name and department, for one of our customers. I used PowerShell for this. Let’s take a look at my steps.

First I installed the necessary tools:

https://msdn.microsoft.com/en-us/library/azure/jj151815.aspx

“First install the Microsoft Online Services Sign-In Assistant for IT Professionals RTW from the Microsoft Download Center. Then install the Azure Active Directory Module for Windows PowerShell (64-bit version), and click Run to run the installer package.”

After that I executed the following Cmdlets

$credential = get-credential
Connect-MsolService -Credential $credential
Get-MsolUser | Select-Object DisplayName, Country | Export-Csv C:\users.csv

You are now able to open the CSV in Excel and have you results ready. Nice 🙂 I am a PowerShell n00b but this was pretty easy to do for me 🙂

ps.

You do need to be an Office 365 Global Administrator to connect through PowerShell.

Jasper Oosterveld

My name is Jasper Oosterveld. I am a Microsoft MVP, Data Security & Microsoft 365 Consultant based in the Netherlands. I’ve spent the last decade helping organizations tackle complex challenges around Governance, Adoption and Data Security with Microsoft Purview. My mission? To empower companies to protect their data and streamline collaboration in Microsoft 365, all while keeping governance and adoption at the forefront.

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.