none
Powershell System.String anomaly

    Question

  • I have a PS script that dumps a bunch of status info from an Exchange 2010 environment and everything works great in EMS. I created a scheduled task which involves running powershell.exe and then importing an Exchange 2010 session. That is where I discovered the following anomaly:

    Steps to repro the problem:

    Start an EMS session as Adminstrator and then also start a normal powershell session as Administrator. In the normal powershell window create an Exchange 2010 session:

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri 'http://exserver01/PowerShell/' -Authentication Kerberos

    Import-PSSession -Session $Session

     

    Now create a the same variable in both of the PS windows with this command:

    $mbxDB = Get-MailboxDatabase <myDB> -status

    In the EMS windows one can run the following command: $mbxdb.DatabaseSize.ToGB() but in the normal PS window I get the following error:

    Method invocation failed because [System.String] doesn't contain a method named 'TOGB'

     

    Upon closer inspection it would appear that System.String in the EMS window and the normal PS window do not have the same properties

    For example mbxdb.DatabaseSize | gm in the normal PS window does not have any of the ToGB, ToMB etc properties.

    Does anyone have a workaround or a solution?

    Thanks

    /Simon

    Monday, June 28, 2010 7:56 AM

Answers

  • Found it.

    The datatype is: Microsoft.Exchange.Data.ByteQuantifiedSize which requries loading the Exchange Data dll

    $dll = "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Microsoft.Exchange.Data.dll"

    [Reflection.Assembly]::LoadFile($dll)

    [Microsoft.Exchange.Data.ByteQuantifiedSize]$obj = $mbxdb.DatabaseSize

    /Simon

    • Proposed as answer by Laeeq Qazi Monday, June 28, 2010 8:58 AM
    • Marked as answer by emma.yoyo Tuesday, June 29, 2010 6:03 AM
    Monday, June 28, 2010 8:09 AM

All replies

  • Found it.

    The datatype is: Microsoft.Exchange.Data.ByteQuantifiedSize which requries loading the Exchange Data dll

    $dll = "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Microsoft.Exchange.Data.dll"

    [Reflection.Assembly]::LoadFile($dll)

    [Microsoft.Exchange.Data.ByteQuantifiedSize]$obj = $mbxdb.DatabaseSize

    /Simon

    • Proposed as answer by Laeeq Qazi Monday, June 28, 2010 8:58 AM
    • Marked as answer by emma.yoyo Tuesday, June 29, 2010 6:03 AM
    Monday, June 28, 2010 8:09 AM
  • On Mon, 28 Jun 2010 07:56:01 +0000, DidiMaao wrote:
     
     
    "DiDiMaao"? YOW! I haven't used that since I left Viet Nam in 1968!
    ---
    Rich Matheisen
    MCSE+I, Exchange MVP
     

    --- Rich Matheisen MCSE+I, Exchange MVP
    Tuesday, June 29, 2010 1:06 AM