locked
PowerShell & EMS differences RRS feed

  • Question

  • 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

    Monday, February 23, 2015 3:41 PM

All replies

  • 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,
    Fred


    There's no place like 127.0.0.1


    • Edited by FWN Monday, February 23, 2015 4:02 PM
    Monday, February 23, 2015 3:51 PM
  • 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


    There's no place like 127.0.0.1

    Thursday, March 12, 2015 10:16 AM