Office 365 Script: Get an Office 365 user statistics report

Need a way to report mailbox statistics and/or mobile device usage information (plus a few other things) to your various business groups or subsidiaries?  Or, perhaps you want to verify that users have been assigned the correct license?  Use the following script to generate a little report – or big report if you have several thousands of users. In order for the script to work, you will need to download and install the Microsoft Online Services Module for Windows PowerShell.  Keep in mind that the script can take a while to run across the internet against Office 365 if you have several thousands of users.

Read the help information for details on how to execute the script.

Get-help .\GetMsolUserReport.ps1 -full

A copy of the script can be downloaded by clicking on the link below.


UPDATED 09/07/2012 

- fixed a couple of typo's resulting from the previous update

UPDATED 08/17/2012

- fixed an issue where the script would throw an error about variable optimization when run using PowerShell v3 pre-release.

UPDATED 05/07/2012

- fixed an issue where department, company, and manager attribute values were not being saved to the file.  Thanks for pointing this out!


Comments (9)

Cancel reply

  1. Anonymous says:

    This is a great script.  Very similar to our Office 365 Reports software.

    Jude, this script does not write any info to your Office 365 environment.

    You should publish it on GITHub for people like Michel-v-V to make additions and improvements.

  2. Anonymous says:

    Hi Thomas,

    First of all thanks for the great script!!!

    I made some adjustments for our (customer) needs (I hope you don't mind) 🙂

    * Added some fields: Country, LastLogon, RecipientTypeDetails

    * Changed the TotalItemSize and DeletedItemSize so that they are calculated in Mb's

    * Changed the delimiter for the CSV (;) because of issues with importing the csv in Excel (with Dutch region settings)

    Do you want me to share these changes in the script?

  3. Lars, thanks for pointing this out.  I must have deleted the lines that collected the department, company, and manager attributes when I was cleaning up commented out lines and stuff.  Those attribute values now appear in the report.  Thanks again!

  4. Jude,

    Looks like I am able to repro the issue under powershell 3.  Will work on updating the script to prevent the error.  Thanks for bringing it to my attention!  

    For everyone else, if you have a powershell 2 system handy, please run the script under ps2.  thanks all!

  5. Angi Livermore says:

    This script is AWESOME!!!!  Thanks for sharing!

  6. Lou Mandich says:

    Great work Thomas!

  7. Thomas Brelinski says:

    Very nice Thomas!!!

  8. Lars B says:

    Great script!

    It did however not export the department attribute for any of the AD accounts from one of my largests clients, so I cannot sort the output? 🙁

    Can this be because of throttling (it's a large tenant)? If so, how do I solve this?

  9. jude says:


    When i run the script, I'm getting the following error. Any ideas on why ?


    Cannot overwrite variable strSecondaryProxyAddresses because the variable has been optimized. Try using the

    New-Variable or Set-Variable cmdlet (without any aliases) or dot the command trying to set the variable.

    At C:UsersJudeDownloadsGetMsolUserReport.ps1:948 char:45

    +             [string]$strSecondaryProxyAddresses += $($_.substring(5)) + ";"

    +                                                      ~~~~~~~~~~~~~~~

       + CategoryInfo          : WriteError: (strSecondaryProxyAddresses:String) [], SessionStateUnauthorizedAccessExcept


       + FullyQualifiedErrorId : VariableNotWritableRare


    And, I just want to know, by running the script, does it 'write' any info to the Office 365 environment ?


Skip to main content