none
EWS managed API: update method for an appointment creates an error message RRS feed

  • Question

  • I have created a powershell script using EWS managed API to update some appointments in my Calender. When I run the sript under my account the script is working properly. But when I run it under another account which is having full maibox access and send as permission the script fails.

    When callin the update() method for an appointment the following message comes up:

    Exception calling "Update" with "2" argument(s): "When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address f
    or any distinguished folder Ids."
    At C:\Documents and Settings\adm.kraehfri\My Documents\Scripts\Sync-Calendar.ps1:61 char:32
    +             $appointment.update <<<< ([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverwrite,
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    Can anybody tell me what I am doing wrong?

    Here is the code I am using (removed some statemants which are not relevant for the problem):

    [system.reflection.assembly]::loadfile("C:\WINDOWS\system32\Microsoft.Exchange.WebServices.dll") | out-null
    $MBXName = "<my mailbox address>"
    #---------------------------------------------------------------------------------------------------------------------+
    # connect to Exchange 2007 SP1                                                                                        !
    #---------------------------------------------------------------------------------------------------------------------+
    $exVersion = New-Object Microsoft.Exchange.WebServices.Data.exchangeversion
    $ews = New-Object Microsoft.Exchange.WebServices.Data.exchangeservice($exversion)

    $ews.UseDefaultCredentials = $true
    $ews.AutodiscoverUrl($MBXName)
    $Mailbox = new-object Microsoft.Exchange.WebServices.Data.mailbox($MBXName)
    $CalendarId = new-object microsoft.exchange.webservices.data.folderId([microsoft.exchange.webservices.data.WellKnownFolderName]::Calendar,$Mailbox)
    $Calendar = [microsoft.exchange.webservices.data.folder]::bind($ews,$CalendarId)
    $StartDate = [system.datetime]"09.1.2012"
    $EndDate = $Startdate.Addmonths(1)
    $CalendarView = New-Object microsoft.exchange.webservices.data.CalendarView($Startdate,$EndDate)
    $Propset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)

    $AppointmentsFound = $ews.FindAppointments($Calendar.Id, $Calendarview)
    if ($AppointmentsFound.items.count -gt 0) {
        [void]$ews.LoadPropertiesForItems($AppointmentsFound.items,$Propset)
    }

    foreach ($appointment in $AppointmentsFound) {
        $appointment.load()
        $appointment.subject
        if ($appointment.isrecurring) {
             do something with recurring meeting    }
        else {
            "$($appointment.start) - $($appointment.end), Category: $($appointment.categories)"
            if ($appointment.organizer.address -eq $MBXName -and !$appointment.MeetingRequestWasSent `
                -and !($appointment.categories -contains "Feiertag" -or $appointment.categories -contains "Holiday")) {
                $appointment.RequiredAttendees.add("<another mailbox address>")
                $appointment.update 

    ([Microsoft.Exchange.WebServices.Data.ConflictResolutionMode]::AlwaysOverwrite,                                [Microsoft.Exchange.WebServices.Data.SendInvitationsOrCancellationsMode]::SendOnlyToAll)
            }
               
        }
    }


    • Edited by Kilitop Thursday, September 6, 2012 1:51 PM
    Wednesday, September 5, 2012 9:17 AM