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
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.
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.
Can not convert value (exchange 2010) to GB or MB
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
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