Scenario: When connecting to Exchange PowerShell without the Exchange management tools installed, you get the following error message when trying to convert the mailbox size to another Size unit. For example: With the Exchange Management tools installed, you can run the following command successfully:
Get-MailboxStatistics user1 | Select {$_.TotalItemSize.Value.ToMB()}
But when you connect to Exchange Powershell via a session without the Exchange Management tools installed, you receive the following error:
Method Invocation failed because [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] does not contain a method named ‘ToMB’
Solution: To work around this problem:
#Collect Mailbox Stats $stat_o365 = get-mailbox -resultsize unlimited | Get-mailboxstatistics #Loop the stats $stat_o365 | %{ $Name = $_.displayname $TIS = [string]$_.TotalItemSize $TDIS = [string]$_.TotalDeletedItemSize #start the value manipulation $regex = [regex]"((.*))" $TISstring = [regex]::match($TIS, $regex).Groups[1] $TDISstring = [regex]::match($TDIS, $regex).Groups[1] $TISString = $TISString -replace "Bytes","" $TDISString = $TDISString -replace "Bytes","" #Convert the strings to Int $TDISValue = [INT]$TDISString $TISValue = [INT]$TISString #Add the Mailbox Size and round to the nearest MB $TotalSize = [Decimal]::Round((($TDISValue + $TISValue)/1024)/1024) }
Another very strong and powerful position. I have been reading through some of my previous posts, and finally decided to leave a comment on this one. I signed up for your newsletter, then please keep posting informative!
IT support Dallas
LikeLike