# Get/convert size from exchange mailbox

**URL:** <https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464>\
**Category:** PowerShell Help\
**Created:** [January 8, 2021, 8:14am UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464 "2021-01-08T08:14:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![paddy75](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@paddy75](https://forums.powershell.org/u/paddy75)\
**Post date:** [January 8, 2021, 8:14am UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/1 "2021-01-08T08:14:45Z")

</div>

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

&nbsp;

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
	}
		[pscustomobject]$props
	}
```

Thanks

---

<div class="post-metadata">

**Author:** ![ralphmwr](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/ralphmwr/32/1064_2.png) [@ralphmwr](https://forums.powershell.org/u/ralphmwr)\
**Post date:** [January 8, 2021, 9:15am UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/2 "2021-01-08T09:15:11Z")

</div>

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
2726297.6

PS C:\Users\micha> $Number.ToString('n')
2,726,297.60

PS C:\Users\micha> $Number.ToString('n0')
2,726,298

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

Recommend reviewing format types in .NET

[https://docs.microsoft.com/en-us/dotnet/standard/base-types/formatting-types](https://docs.microsoft.com/en-us/dotnet/standard/base-types/formatting-types)

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
1073741824
```

---

<div class="post-metadata">

**Author:** ![paddy75](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@paddy75](https://forums.powershell.org/u/paddy75)\
**Post date:** [January 8, 2021, 11:04am UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/3 "2021-01-08T11:04:22Z")

</div>

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;}

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [January 10, 2021, 9:11am UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/4 "2021-01-10T09:11:28Z")

</div>

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

```
$mailboxstats.TotalItemSize.value.ToBytes()
```

---

<div class="post-metadata">

**Author:** ![paddy75](https://avatars.discourse-cdn.com/v4/letter/p/35a633/32.png) [@paddy75](https://forums.powershell.org/u/paddy75)\
**Post date:** [January 10, 2021, 10:41am UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/5 "2021-01-10T10:41:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [January 10, 2021, 9:07pm UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/6 "2021-01-10T21:07:30Z")

</div>

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

```
$mailboxstats.TotalItemSize

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

$mailboxstats.TotalItemSize.value.ToBytes()

303129923
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/get-convert-size-from-exchange-mailbox/15464/7 "2024-05-16T20:28:02Z")

</div>

Closed on May 16, 2024, 8:28pm UTC


