Page 1 of 1

Can not convert value (exchange 2010) to GB or MB

Posted: Mon Nov 05, 2012 1:14 am
by rtiel1
I'm running the following script succesfully in Exchange Management Shell and in Powergui, but in Powerstudio 2012 (the latest version) it fails. For some reason it cannot convert the value and I receive the error "Method invocation failed because [System.String] doesn't contain a method named 'ToGB'."

script:
$Databases = Get-MailboxDatabase -Status
foreach($Database in $Databases) {
$DBSize = $Database.DatabaseSize
$MBCount = @(Get-MailboxStatistics -Database $Database.Name).Count

$MBAvg = Get-MailboxStatistics -Database $Database.Name |
%{$_.TotalItemSize.value.ToMb()} |
Measure-Object -Average

New-Object PSObject -Property @{
Server = $Database.Server.Name
DatabaseName = $Database.Name
LastFullBackup = $Database.LastFullBackup
MailboxCount = $MBCount
"DatabaseSize (GB)" = $DBSize.ToGB()
"AverageMailboxSize (MB)" = $MBAvg.Average
"WhiteSpace (MB)" = $Database.AvailableNewMailboxSpace.ToMb()
}
}

Any ideas?

Can not convert value (exchange 2010) to GB or MB

Posted: Mon Nov 05, 2012 1:26 am
by rtiel1
My mistake,

I was calling the exchange shell via the command New-PSSession. To get this script working I have to call the Exchange snappins Add-PSSnapin otherwise for some reason the .ToGB() won't work.

Remco