Wednesday 1 February 2012

Changing byte metrics in Powershell to MB or GB

By using Get-Mailbox and piping this to Get-MailboxStatistics, data is returned in varying metrics based on the actual mailbox size the users have.


To streamline this you can convert all values to MB or GB by using the following:


MB
Get-Mailbox -ResultSize unlimited Get-MailboxStatistics Sort-Object TotalItemSize -Descending ft @{label="Total Size (MB)";expression={$_.TotalItemSize.Value.ToMB()}} -auto out-file "X:\report.csv"

GB
Get-Mailbox -ResultSize unlimited Get-MailboxStatistics Sort-Object TotalItemSize -Descending ft @{label="Total Size (GB)";expression={$_.TotalItemSize.Value.ToGB()}} -auto out-file "X:\report.csv"




Where "X:\report.csv" is the where you want the file to be created.


Please note this simply exports the mailbox size values in MB or GB. It does not append the DisplayName of the user or anything else.


Take Care


Oliver Moazzezi MVP - Exchange Server

No comments: