Link to home
Start Free TrialLog in
Avatar of AMU1962
AMU1962

asked on

Exchange Web Services and Exchange 2010 SP3

All,

I have a script (a few scripts actually) that I'm trying to run in the Exchange Management Shell. We have Exchange 2010 SP3 on 2008 R2 server with SP1. I have downloaded and tried EWS API version 1.2 and 2.0. I keep getting a Bind error in various small scripts. ie

exception calling "Bind" with "2" argument(s): "The specified object was not found in the store."
At D:\development\powershell\sjemail2.ps1:34 char:66
+ $InboxFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind <<<< ($service,$folderid)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

The relevant bits of code in each script are :

[Reflection.Assembly]::LoadFrom("C:\Program Files\Microsoft\Exchange\Web Services\2.0\Microsoft.Exchange.WebServices.dll")
$service =  New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)

if ($credential -ne $null)
{    
      Write-Host "Credential OK"  
      $credential.GetNetworkCredential()
}
else  
{    
      Write-Host "Problem with Credential"  
      $service.UseDefaultCredentials = $true;
}    

function GetUnreadInboxMails([string] $emailAddress)  
{    
      Write-Host "In GetUnreadInboxMails"  
      Write-Host $emailaddress
      $service.AutodiscoverUrl($emailAddress, {$true});          
      $mailbox = New-Object Microsoft.Exchange.WebServices.Data.Mailbox($emailAddress)    
      Write-Host $mailbox
          $folderId = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox, $mailbox)      
      Write-Host $folderId      
      Write-Host "Before folder"      
      $folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderId);    
      Write-Host "After folder"      


I have double checked the EWS directory, which is OK. The error always happens at the line
$folder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folderId);  

I have read on some forums that this is an indication of access rights problems. We also have Exchange 2010 SP3 and was wondering which version of EWS I should be using and do I need to change the entry in the following code to reflect I'm using SP3 .....
$service =  New-Object Microsoft.Exchange.WebServices.Data.ExchangeService -ArgumentList([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010)



Thanks
ASKER CERTIFIED SOLUTION
Avatar of achaldave
achaldave
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of AMU1962
AMU1962

ASKER

Thanks  achaldave

Reading through your recommandations pointed me to a permissions problem.

Here is the exact link to the solution I used.

http://social.technet.microsoft.com/Forums/exchange/en-US/d3be112f-24bf-43e8-80ae-de35c9a369bd/unable-to-log-on-to-owa-addmailboxpermissions-vs-addadpermissions?forum=exchangesvradminlegacy

Thanks

AMU