Get folders and sizes for all mailboxes using Exchange Shell

Get folders and sizes for all mailboxes using Exchange Shell

Last updated on March 30th, 2023 at 05:10 pm

Read Time:2 Minute, 39 Second

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!

Feedback

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]

Free Subscription

If you want to be notified when we post more quality guides like this one, sign up to our free subscription service and you will receive an email when a new post is live.

Join 441 other subscribers.

No need to worry, we will not be filling your inbox with spam and you can unsubscribe anytime you like.


Leave us a message...

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