A graphic with a blue background featuring an icon of a document with a command prompt symbol, alongside text that reads "Get folders and sizes for all mailboxes using Exchange Shell.

We recently had a request to provide to our Project Management team, a full list of all Exchange mailboxes with all folders within each mailbox and also the total sizes of each folder for each mailbox.

This came as a bit of a shock to us and we still have no idea why they wanted it, but, us techies just get told to do what is needed and not ask questions!

Our first thought was to get some of the Project Management team analysts setup with a basic administrator account on our Exchange and get them to go through it manually. Then we thought that was a bit cruel given that there was over 3500 mailboxes that needed this work carrying out on. Then on the other hand, we did not want to sit there going through all the mailboxes either!

So, then we turned to PowerShell

Once again, the saviour of all techies that do not want to do unnecessary work – PowerShell!

Of course there is a PowerShell script that you can use to carry out this task – there is a PowerShell script for everything, the hard part is finding the correct script for what the data that you want to get.

So between three of us that know PowerShell on an OK basis, we started to put together a basic script that would get the mailboxes, get the statistics, select the data we needed and then show it to us.

PowerShell Script

Below is the PowerShell that we managed to put together to get us the information that we had been asked to provide:

Get-Mailbox | Select-Object alias | foreach-object {Get-MailboxFolderStatistics -Identity $_.alias | select-object Identity, ItemsInFolder, FolderSize}

It seemed to have worked, but all we had was a (very long) page of data. so, we obviously needed to provide it to our Project Management team in a nice pretty Excel spreadsheet.

Export to CSV

This is where we now needed to take the data we had and export it into CSV. Anyone that has used PowerShell will already know this, but just in case, you need to add the pipe export-csv part to the end of the script. So, from using our above script, we would use this:

Get-Mailbox | Select-Object alias | foreach-object {Get-MailboxFolderStatistics -Identity $_.alias | select-object Identity, ItemsInFolder, FolderSize} | export-CSV "C:\mailboxdata.csv"

We then took this CSV file, saved it as a XLSX file format, formatted the data a bit in Excel and created some pointless graphs (PM’s love graphs) and sent it off to our Project Management team.

They were stunned that we had managed to get such a large amount of data to them within the same morning and even questioned whether it was correct or “rushed”. Imagine that, Project Managers questioning the IT Department – whatever next! (sarcasm is meant there…).

So, they were happy, we were happy, everyone was happy. Hopefully you will be too if you can reuse this PowerShell script to impress your PMs or bosses!


We would love to hear your feedback on this article so come and join us on Facebook or Twitter and let us know what you think!

Click to rate this post!
[Total: 0 Average: 0]

Discover more from TechyGeeksHome

Subscribe to get the latest posts to your email.

Avatar for Andrew Armstrong

Andrew Armstrong

Founder of TechyGeeksHome and Head Editor for over 15 years! IT expert in multiple areas for over 26 years. Sharing experience and knowledge whenever possible! Making IT Happen.

Leave us a message...

This site uses Akismet to reduce spam. Learn how your comment data is processed.