none
Seaching Exchange 2007 shared mailbox (Powershell) RRS feed

  • Question

  • I'm trying to search a shared mailbox using Powershell and I'm having some difficulties. When I call the findItems Method in my script, I get this error:

    Exception calling "FindItems" with "3" argument(s): "An element node 'soap:Envelope' of the type Element was expected, but 
    node 'Autodiscover' of type Element was found."
    At line:14 char:23
    + $exchService.FindItems <<<< ($folder, $searchFilters, $view)
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Here's my code:

    $exchVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2007_SP1
    $exchService = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService($exchVersion)
    $cred = New-Object System.Net.NetworkCredential("user", "password", "domain") #credentials of the account who has access to the shared mailbox
    $exchService.Url = "https://webmail.domain.com/Autodiscover/Autodiscover.xml"
    $exchService.Credentials = $cred
    $mb = New-Object Microsoft.Exchange.WebServices.Data.Mailbox("email@domain.com") #email address of the shared mailbox
    $folder = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox, $mb)
    $view = New-Object Microsoft.Exchange.WebServices.Data.ItemView("10")
    $searchFilters = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring([Microsoft.Exchange.WebServices.Data.ContactSchema]::DisplayName, "@John Doe")
    
    $exchService.FindItems($folder, $searchFilters, $view)

    My goal is for the script to return a collection of the items in the inbox sent from "John Doe"

    Thanks for any help


    Friday, March 8, 2013 4:22 PM

All replies

  • With

    $exchService.Url = "https://webmail.domain.com/Autodiscover/Autodiscover.xml"

    This is incorrect it needs to point to your EWS url (which if you have autodiscover setup properly you should be able to discover. If not you could hard-code with something like

    $uri=[system.URI] "https://webmail.domain.com/ews/exchange.asmx"  
    $service.Url = $uri  
    Cheers
    Glen
    Monday, March 11, 2013 5:55 AM