- Manage Azure Policy using Terraform - Tue, Aug 2 2022
- Getting started with Terraform in Azure - Tue, Jul 12 2022
- Azure Bicep: Getting started guide - Fri, Nov 19 2021
One common Exchange administrative task is to find the total size of mailboxes in the environment. This can be useful to find the biggest mailboxes or ones that are (nearly) empty as targets for removal due to inactivity. However, mailbox sizes are only available via PowerShell, and depending on where you run the Get-MailboxStatistics command, the options for sorting the output may require additional work.
First, what exactly is the problem with the default output? When viewing the size of multiple mailboxes through the TotalItemSize property, each mailbox does not have a standard unit. Instead, it converts mailboxes to a byte unit that best represents their sizes, like so:
We have different mailboxes with KB, MB, and GB listed. If you tried to sort the mailboxes by their TotalItemSize, the Exchange PowerShell module could do so, but if you exported this data to Excel, you couldn't sort it.
So what are the options if you need to export the data to another format? The Exchange PowerShell module also includes the ability to convert these values to a common byte unit. The TotalItemSize has built-in methods to convert to bytes, kilobytes (KB), megabytes (MB), gigabytes (GB), and terabytes (TB). You can view these methods by passing the value of TotalItemSize to Get-Member:
To apply these methods to the TotalItemSize property and display the data along with other mailbox statistics, PowerShell allows creating a calculated property in the output. This lets you create a custom property name and use an expression to display its value. Here are some examples for a single mailbox and multiple mailboxes. Notice that in the Expression property, the ToMB() method serves to calculate each mailbox's size to megabytes:
Get-MailboxStatistics -Identity gglass | Select-Object DisplayName, @{Name="TotalItemSizeMB";Expression={$_.TotalItemSize.Value.ToMB()}}, ItemCount Get-Mailbox | Get-MailboxStatistics | Select-Object DisplayName, @{Name="TotalItemSizeMB";Expression={$_.TotalItemSize.Value.ToMB()}}, ItemCount
Now this is great if you run these commands in an Exchange PowerShell module window. But these methods are not available when using a remote PowerShell session connected to the Exchange server (for example, this would apply to Exchange Online in Office 365). The command will not return an error, but the calculated property would simply be blank.
In this case, we would need to manipulate the TotalItemSize value manually to extract the raw bytes in the string and convert them to the desired byte unit. The calculated property formula I have always used comes from this Scripting Guy! blog post from Brian Jackett. Here is an example of the formula he uses in a calculated property:
Get-MailboxStatistics -Identity gglass | Select-Object DisplayName, @{Name="TotalItemSizeMB"; Expression={[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),0)}}, ItemCount
Let's break out his conversion:
[math]::Round(($_.TotalItemSize.ToString().Split("(")[1].Split(" ")[0].Replace(",","")/1MB),0)
First, he converts the TotalItemSize property to a string using a built-in method on the TotalItemSize property. Then he splits it on any opening parentheses and keeps the element at index 1. At this point, this is everything after the first parentheses in TotalItemSize:
Next, he splits the string again on any spaces and keeps the element at index 0. This should get just the number portion of the string. After that, he removes any commas:
Finally, he converts the byte count to megabytes by using the built-in PowerShell converter /1MB. Additional, he uses the .NET framework method [math]::Round to round the value to an integer with the option to specify the number of decimals to use (in this case, "0" is specific to give a nice round number):
The final output then looks like this:
Subscribe to 4sysops newsletter!
While a little complicated and messy, this example does show the power of what's possible using different methods to manipulate strings into meaningful values. Now we can export this to CSV or a similar format and use the calculated property TotalItemSizeMB to sort the values as needed.
Hi.
I have to move my 60 mailbox (from Office 365 online) to another Office 365 tennant.
Could you help me?.
Greetings.
Hi Javier, I won’t be able to assist but I suggest reading over this Office Support article. I believe it was announced at Ignite 2017 that Microsoft was working on a tenant to tenant migration option, but for now I would suggest contacting a third-party vendor who specializes in this type of migration or perhaps a Microsoft partner to assist.
https://support.office.com/en-us/article/how-to-migrate-mailboxes-from-one-office-365-tenant-to-another-65af7d77-3e79-44d4-9173-04fd991358b7
Are you aware of a similar method for Get-MailboxFolderStatistics? I would often use this command searching for FolderSize to get a list of folder sizes for users to determine where the bulk of their emails are located.
Check out this link, haven't tried it myself but since Exchange Online is a remote PS session, might help:
powershell – Exchange Get-MailboxFolderStatistics FolderSize to MB – Stack Overflow
I am sorry to vent my frustration here, but to me what this shows in the first place is that some (many/most??) employees at Microsoft do not have the slightest idea how to provide good APIs/data structures.
Who came up with the idea to NOT show the size in bytes? If I use Powershell I write programs/scripts and need to compare basic numbers and not human-readable text strings. If I need those, I provide them myself, thank you.