PowerShell & EMS differences

Hi all,

apologies if this has been asked before but I couldn't find an answer.

If I run this in EMS it works perfectly

$size = '{0:N2}' -f  ((get-mailboxdatabase $_.name -status).databasesize.ToMB()/1024)

However if I run it from PowerShell and I connect to Exchange I get "method invocation failed because....doesn't contain a method named "ToMB"

I would prefer it so it can be run from powershell so that I can add it to the task schedule and to also give it to the support team who may not have access to the exchange server to run it remotely.

TIA

Andy

February 23rd, 2015 10:42am

Hi Andy,

this is because when you connect to Exchange using a regular Powershell console you do not locally have the types. Your console does not know how a Mailbox Database object is supposed to look which unfortunately means you don't get the methods (like ToMB()).

You will have to drop the ".ToMB()" part from your code and parse the text to get the correct result.

Cheers,

Free Windows Admin Tool Kit Click here and download it now
February 23rd, 2015 10:52am

Hi Andy,

in case you are using Exchange 2010, here's another way:

If you use the function-script Import-ModuleExchange to connect to Exchange from a regular powershell-console, everything should work as it does in the Exchange Management Shell.

Cheers,
Fred

March 12th, 2015 6:17am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics