locked
Need help with powershell and EWS... RRS feed

  • Question

  • Any idea why this code works on two other workstations but doesn't work on another?  I've included the code and here is the error I'm getting:

    Exception calling "AutodiscoverUrl" with "1" argument(s): "The type initializer for 'Microsoft.Exchange.WebServices.Strings' threw an exception."

    At line:14 char:29

    + $exchService.AutodiscoverUrl <<<< ($mailbox)

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : DotNetMethodException

     $mailbox = 'xxxxx@yyyy.com'
    
    Import-Module -Name "C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll"
    
    $exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP2)
    
    $exchService.UseDefaultCredentials = $true
    
    $exchService.AutodiscoverUrl($mailbox)


    Anthony

    Wednesday, September 19, 2012 12:43 PM

Answers

  • Does the affected machine have the same version of the .Net framework as the others?  Can you verify that the good ones are not running a later version?

    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    • Marked as answer by emma.yoyo Wednesday, September 26, 2012 2:56 AM
    Wednesday, September 19, 2012 3:09 PM
  • Hi Anthony,

    Any updates?

    By the way, I would also suggest you seek the solution in the Development forum:

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Frank Wang

    TechNet Community Support

    • Marked as answer by emma.yoyo Wednesday, September 26, 2012 2:56 AM
    Thursday, September 20, 2012 9:07 AM

All replies

  • Sorry to ask such an obvious question, but have you definitely installed the EWS Managed API dll on the affected workstation, and is it at the same location

    C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll

    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Wednesday, September 19, 2012 1:04 PM
  • Yes.  I installed versions 1.1, 1.2, and 2.0 on all three workstations.  The script works using all three versions of the .dll on workstations 1 and 2.  My new workstation, workstation 3, fails with the erorr I indicated.

    Anthony

    Wednesday, September 19, 2012 1:21 PM
  • The error message it's giving isn't the most helpful.  Is there anything in any of the event logs?

    Does it make any difference if you tell it to not use the default credentials, and supply some explicitly?

    Or, is it practical to hard-code the url, rather than autodiscover it?


    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    Wednesday, September 19, 2012 1:36 PM
  • I was running from powergui.  When I ran from the powershell command line I received this error:

    Import-Module : Could not load file or assembly 'file:///C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.


    Anthony

    Wednesday, September 19, 2012 2:58 PM
  • Does the affected machine have the same version of the .Net framework as the others?  Can you verify that the good ones are not running a later version?

    Mobile OWA For Smartphone
    www.leederbyshire.com
    email a@t leederbyshire d.0.t c.0.m

    • Marked as answer by emma.yoyo Wednesday, September 26, 2012 2:56 AM
    Wednesday, September 19, 2012 3:09 PM
  • Hi Anthony,

    Any updates?

    By the way, I would also suggest you seek the solution in the Development forum:

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads

    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Frank Wang

    TechNet Community Support

    • Marked as answer by emma.yoyo Wednesday, September 26, 2012 2:56 AM
    Thursday, September 20, 2012 9:07 AM
  • Hi Anthony,

    Any updates?


    Frank Wang

    TechNet Community Support

    Monday, September 24, 2012 1:46 AM