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

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
rtiel1
Posts: 15
Joined: Thu Jul 26, 2012 11:34 pm

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

Post by rtiel1 » Mon Nov 05, 2012 1:14 am

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?

User avatar
rtiel1
Posts: 15
Joined: Thu Jul 26, 2012 11:34 pm

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

Post by rtiel1 » Mon Nov 05, 2012 1:26 am

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