Get/convert size from exchange mailbox

Hello all,

if I look for the quota limits in exchange the result is something like this:

IssueWarning : 1 GB (1,073,741,824 bytes)
ProhibitSend : 1.5 GB (1,610,612,736 bytes)
ProhibitSendReceive : 2 GB (2,147,483,648 bytes)
TotalItemSize : 86.13 MB (90,314,712 bytes)

with this it is harder to calculate because it has MB, GB, bytes comma in the output. How i can get a real number? Only bytes what is displayed for example? Then i can convert it in an other unit i what i need.

for example:

1 GB (1,073,741,824 bytes) --> should be 1073741824
1.5 GB (1,610,612,736 bytes) --> should be 1610612736
2 GB (2,147,483,648 bytes) --> should be 2147483648
86.13 MB (90,314,712 bytes) --> should be 90314712


The code i have at the moment:

#get all mailboxes where Quota is not default
$mailboxes = get-mailbox -ResultSize Unlimited | Where-Object {$_.UseDatabaseQuotaDefaults -ne $true -and $_.alias -notlike '*Search*'}

$results = ForEach ($mb in $mailboxes)
	$stats = get-mailboxstatistics $mb
	$props = [ordered]@{
		'DisplayName' = $mb.displayname
		'DB'  = $stats.databasename
		'IssueWarning' = $mb.IssueWarningQuota
		'ProhibitSend' = $mb.ProhibitSendQuota
		'ProhibitSendReceive' = $mb.ProhibitsendReceiveQuota
		'TotalItemSize' = $stats.totalitemsize


I don’t have an exchange environment to test. What data type are those object properties (strings, int)? The code you posted assigns all output to variables. I’m assuming you are displaying the $props collection and that is where you get a display you don’t want. If those properties are strings, you’ll have to parse them which is a little more complicated, but if they are a number data type, you just need to format them as you like with the ToString() method. Here are a couple examples:

Formatting Numbers:

PS C:\Users\micha> $Number = 2.6MB

PS C:\Users\micha> $Number

PS C:\Users\micha> $Number.ToString('n')

PS C:\Users\micha> $Number.ToString('n0')

PS C:\Users\micha> $Number * 1kb

Recommend reviewing format types in .NET

Parsing String with a simple conversion function:

function convertto-databytes([int64]$Num, [string]$Size)
>> {
>>     switch ($Size)
>>     {
>>         'KB' {$Num * 1KB}
>>         'MB' {$Num * 1MB}
>>         'GB' {$Num * 1GB}
>>     }
>> }
>> $NumberString = "1 GB (1,073,741,824 bytes)"
>> $Numpart, $Size, $format = -split $NumberString
>> convertto-databytes -Num $Numpart -Size $Size

Here is what i get with get-mailbox | get-member
TypeName: Microsoft.Exchange.Data.Directory.Management.Mailbox

Name: IssueWarningQuota
MemberType: Property
Definition: Microsoft.Exchange.Data.Unlimited[Microsoft.Exchange.Data.ByteQuantifiedSize] IssueWarningQuota {get;set;}

Take a closer look at the output of Get-Member

$mailboxstats.TotalItemSize | Get-Member

   TypeName: Microsoft.Exchange.Data.Unlimited`1[[Microsoft.Exchange.Data.ByteQuantifiedSize, ...]]

Name        MemberType Definition
----        ---------- ----------
CompareTo   Method     int CompareTo(Microsoft.Exchange.Data.Unlimited[Microsoft.Exchange.Data.ByteQuantifiedSize] o...
Equals      Method     bool Equals(System.Object other), bool Equals(Microsoft.Exchange.Data.ByteQuantifiedSize othe...
GetHashCode Method     int GetHashCode()
GetType     Method     type GetType()
ToString    Method     string ToString(), string ToString(string format, System.IFormatProvider formatProvider), str...
IsUnlimited Property   bool IsUnlimited {get;}
Value       Property   Microsoft.Exchange.Data.ByteQuantifiedSize Value {get;set;}

Now if you inspect the value property

$mailboxstats.TotalItemSize.value | Get-Member

   TypeName: Microsoft.Exchange.Data.ByteQuantifiedSize

Name          MemberType Definition
----          ---------- ----------
CompareTo     Method     int CompareTo(Microsoft.Exchange.Data.ByteQuantifiedSize other), int IComparable.CompareTo(...
Equals        Method     bool Equals(System.Object obj), bool Equals(Microsoft.Exchange.Data.ByteQuantifiedSize other)
GetHashCode   Method     int GetHashCode()
GetType       Method     type GetType()
RoundUpToUnit Method     uint64 RoundUpToUnit(Microsoft.Exchange.Data.ByteQuantifiedSize+Quantifier quantifier)
ToBytes       Method     uint64 ToBytes()
ToGB          Method     uint64 ToGB()
ToKB          Method     uint64 ToKB()
ToMB          Method     uint64 ToMB()
ToString      Method     string ToString(), string ToString(string format), string ToString(string format, System.IF...
ToTB          Method     uint64 ToTB()

Now we can simply use the ToBytes() method


yes, i know. I spend a lot of time to try the implemention in my script. but wihout luck. is there no other way to replace everything outside the bracket, then remove the brackets and commas?

ToBytes() outputs just the numbers in the parenthesis. Exactly what you are asking for.


    IsUnlimited Value
    ----------- -----
            False 289.1 MB (303,129,923 bytes)