Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET! Learn What IT Pros Need to Know About Windows 11 - August 24th at 1 PM ET!
Cloud Computing

Export Office 365 Users to a CSV File

Organizations with large Office 365 deployments may need to export user information to a comma delimited file (CSV), which can then be used as the basis for creating reports. In this Ask the Admin, I’ll show you how to connect to Office 365 and export user information using PowerShell.

Setup PowerShell Management for Office 365

Before you can run PowerShell commands to manage or export information from Office 365, you need to make sure that you have the PowerShell cmdlets for Windows Azure Active Directory installed locally, along with the latest version of the Microsoft Online Services Sign-In Assistant. For more information on installing these components, see “How to Install the Windows PowerShell Cmdlets for Windows Azure AD and Office 365” on Petri IT Knowledgebase.

Export Office 365 User Information

First you need to authorize to Office 365 using an administrator account.

  • Log in to Windows 8 and switch to the Start screen.
  • Type powershell, make sure that Windows Azure Active Directory module for PowerShell is selected in the search results and press CTRL+SHIFT+ENTER to launch the console with administrative privileges. Give consent or enter administrative privileges if prompted.
  • In the PowerShell console, type connect-msolservice and press Enter.
  • In the pop-up Enter Credentials dialog, enter your Office 365 administrative username and password, and click OK.

Now that we are successfully authorized to Office 365, we can run the following command to get a list of licensed users:

Sponsored Content

Read the Best Personal and Business Tech without Ads

Staying updated on what is happening in the technology sector is important to your career and your personal life but ads can make reading news, distracting. With Thurrott Premium, you can enjoy the best coverage in tech without the annoying ads.

Get-MsolUser | Where-Object { $_.isLicensed -eq “TRUE” }

Now let’s format the output and send it to a file:

Exporting Office 365 users with PowerShell
Exporting Office 365 users with PowerShell.

Get-MsolUser | Where-Object { $_.isLicensed -eq “TRUE” } | Select-Object UserPrincipalName, DisplayName, Country, Department | Export-Csv c:\LicensedUsers.csv

Alternatively, if you don’t need a file to be generated and just want to work with the data quickly, you can use PowerShell’s OutGrid view.

Get-MsolUser | Where-Object { $_.isLicensed -eq “TRUE” } | Select-Object UserPrincipalName, DisplayName, Country, Department | Out-Gridview

Related Topics:

IT consultant, Contributing Editor @PetriFeed, and trainer @Pluralsight. All about Microsoft, Office 365, Azure, and Windows Server.

Register for Advanced Microsoft 365 Day!

GET-IT: Advanced Microsoft 365 1-Day Virtual Conference - Live August 24th!

Join us on Tuesday, August 24th and hear from Microsoft MVPs and industry experts about how to take advantage of Microsoft 365 at a technical level and dive deep into the features and functionality that will make your environment more secure and compliant.


Sponsored By