TIP: Exchange TotalItemSize.Value.ToMB or ToGB Stopped Working

This is small but valuable TIP as at least 2-3 people already contacted me for this.

TotalItemSize.Value.TOMB() which use to work for Get-MailboxStatistics, admins used it to fetch the mailbox sizes details in MBs or GBs is no longer working.

Here is the command many System Administrators used in onpremise, I am not aware if that ever worked in online world or not.

Get-mailbox -resultsize unlimited | Get-MailboxStatistics | Select-object @{label=”User”;expression={$_.DisplayName}},ServerName,Database,@{label=”Total Size (MB)”;expression={$_.TotalItemSize.Value.ToMB()}},@{label=”Total Delected Size (MB)”;expression={$_.TotaldeletedItemSize.Value.ToMB()}} | Export-Csv c:\temp\O365mbxs.csv -notypeinfo

Here is the Solution to it using powershell math magic in expression, which I found somewhere and added a little modification

expression={[math]::Round(($_.TotalItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}}

You can do the same for GBs as well by modifying the expression a bit.

expression={[math]::Round(($_.TotalItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1024MB),2)}}

Operation for extracting the details in MBs:

Get-mailbox -resultsize unlimited | Get-MailboxStatistics | Select-object @{label=”User”;expression={$_.DisplayName}},ServerName,Database,@{label=”Total Size (MB)”;expression={[math]::Round(($_.TotalItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}},@{label=”Total Deleted Size (MB)”;expression={[math]::Round(($_.TotaldeletedItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1MB),2)}} | Export-Csv c:\temp\O365mbxs.csv -notypeinfo

Operation for extracting the details in Gbs:

Get-mailbox -resultsize unlimited | Get-MailboxStatistics | Select-object @{label=”User”;expression={$_.DisplayName}},ServerName,Database,@{label=”Total Size (GB)”;expression={[math]::Round(($_.TotalItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1024MB),2)}},@{label=”Total Deleted Size (GB)”;expression={[math]::Round(($_.TotaldeletedItemSize.value.ToString().Split(“(“)[1].Split(” “)[0].Replace(“,”,””)/1024MB),2)}} | Export-Csv c:\temp\O365mbxs.csv -notypeinfo

I hope this TIP will assist many of the System admins trying to fix their old logic that was being used in onpremise with previous versions of exchange server.

 

Thanks for reading…

Tech Wizard

https://techwizard.cloud

https://syscloudpro.com/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s