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 LICENSE NUMBERS, ACTIVATION 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.
This topic is 11 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

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

Post 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?
User avatar
rtiel1
Posts: 15
Last visit: Tue Nov 19, 2019 12:05 am

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

Post 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
This topic is 11 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.