I'm having very weird behavior, I get above mentioned error running following simple command:
$user = get-mailbox JoeD | get-mailboxstatistics
$user.totalitemsize.value.toMB()
The issue is that if I run it from "Exchange PowerShell Console" (the one you get with installation of EX management tools) it works without problem and output is as expected number - size of user mailbox in MB. However If I run it from regular
PS session where I imported Exchange snapin it doesn't work... (so it doesn't work from script, for example)
Where is the problem?
The all code of script that doesn't work:
$EXSession = new-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURIhttp://cas.corp.com -authentication Kerberos
import-pssession $EXSession
Add-PSSnapin MIcrosoft.Exchange.Management.POwershell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
connect-exchangeserver mailbox.corp.com
$user = get-mailbox kucerl | get-mailboxstatistics
$user.totalitemsize.value.toMB()