Last Update: Sep 04, 2024 | Published: Feb 25, 2014
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.
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.
First you need to authorize to Office 365 using an administrator account.
Now that we are successfully authorized to Office 365, we can run the following command to get a list of licensed users:
Get-MsolUser | Where-Object { $_.isLicensed -eq “TRUE” }
Now let’s format the output and send it to a file:
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