Here are few tips how to work with ByteQuantifiedSize (Microsoft.Exchange.Data.ByteQuantifiedSize – Microsoft.Exchange.Data.dll) that is typical for Exchange sizes such as TotalDeletedItemSize, FolderSize, TotalItemSize, RecoverableItemsQuota, AvailableNewMailboxSpace etc.
# Example for BQS property
[PS] C:\> Get-MailboxStatistics filip |select TotalItemSize
TotalItemSize
-------------
4.38 MB (4,592,642 bytes)
# Get BQS value
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value
4.38 MB (4,592,642 bytes)
# Check BQS methods especially ToBytes, ToKB, ToMB, ToGB, ToTB
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.value|Get-Member
TypeName: Microsoft.Exchange.Data.ByteQuantifiedSize
Name MemberType Definition
---- ---------- ----------
CompareTo Method int CompareTo(Microsoft.Exchange.Data.ByteQuantifiedSize other)
Equals Method bool Equals(System.Object obj), bool Equals(Microsoft.Exchange.Data.ByteQuantifiedSize other)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
RoundUpToUnit Method System.UInt64 RoundUpToUnit(Microsoft.Exchange.Data.ByteQuantifiedSize+Quantifier quantifier)
ToBytes Method System.UInt64 ToBytes()
ToGB Method System.UInt64 ToGB()
ToKB Method System.UInt64 ToKB()
ToMB Method System.UInt64 ToMB()
ToString Method string ToString(), string ToString(string format), string ToString(string format, System.IF...
ToTB Method System.UInt64 ToTB()
# Get BQS value (4.38 MB) in bytes
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value.toBytes()
4592642
# Get BQS values in bytes from more objects
[PS] C:\> Get-Mailbox -Anr "fil"|Get-MailboxStatistics |%{$_.TotalItemSize.Value.toBytes()}
590853774
986147186
13339213
15511742
# Be careful to use BQS methods like ToGB because output is UInt64 (4.38 MB in GB?)
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value.toGB()
0
# Get BQS as Double
[PS] C:\> (Get-MailboxStatistics filip).TotalItemSize.Value.toBytes()/1GB
0.00427722744643688
# Select BQS value as needed
[PS] C:\> Get-MailboxStatistics filip|select @{Name='TotalItemSizeBytes';Expression={$_.TotalItemSize.Value.toBytes()/1GB}}
TotalItemSizeBytes
------------------
0.00427722744643688
# BQS value as string
[PS] C:\> $string=(Get-MailboxStatistics filip).TotalItemSize.Value.toString()
[PS] C:\> $string="4.38 MB (4,592,642 bytes)"
# Get bytes from BQS string
[PS] C:\> $string|%{($_.Substring($_.indexof("(")+1,$_.indexof("b")-$_.indexof("(")-2)) -replace(",","")}
4592642
# Get BQS string in GB
[PS] C:\> ($string|%{($_.Substring($_.indexof("(")+1,$_.indexof("b")-$_.indexof("(")-2)) -replace(",","")})/1GB
0.00427723117172718
# Parse BQS string
[PS] C:\> [Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse("$string")
4.38 MB (4,592,642 bytes)
[PS] C:\> ([Microsoft.Exchange.Data.ByteQuantifiedSize]::Parse("$string")).gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ByteQuantifiedSize System.ValueType
# Invalid measuring for BQS values - ERROR
[PS] C:\> Get-Mailbox -Anr "fil"|Get-MailboxStatistics| Measure-Object -Sum -Average -Maximum -Minimum -Property TotalItemSize
Measure-Object : Input object "14.79 MB (15,511,742 bytes)" is not numeric.
At line:1 char:62
+ Get-Mailbox -Anr "fil"|Get-MailboxStatistics| Measure-Object <<<< -Sum -Average -Maximum -Minimum -Property TotalItemSize
+ CategoryInfo : InvalidType: (14.79 MB (15,511,742 bytes):Unlimited`1) [Measure-Object], PSInvalidOperat ionException
+ FullyQualifiedErrorId : NonNumericInputObject,Microsoft.PowerShell.Commands.MeasureObjectCommand
# Measure BQS values
[PS] C:\> Get-Mailbox -Anr "fil"|Get-MailboxStatistics|%{$_.TotalItemSize.Value.toBytes()}| Measure-Object -Sum -Average -Maximum -Minimum
Count : 4
Average : 401522533
Sum : 1606090132
Maximum : 986385403
Minimum : 13339213
Property :
# Measure BQS values as needed
[PS] C:\>Get-Mailbox -Anr "koch"|Get-MailboxStatistics|%{$_.TotalItemSize.Value.toBytes()}| Measure-Object -Sum |select@{Name='TotalMailboxSizeGB';Expression={$_.sum/1GB}}
TotalMailboxSizeGB
------------------
1.49578799679875