Exchange online, EWS and PowerShell: Error when updating contact RRS feed

  • Question

  • Hi All

    A customer came with the question to update an address book of a shared mailbox, so that everything is filled in in the correct way. The best solution in my eyes, was to use Exchange Web Services. Then it can run independently from any computer/network etc.

    My connection to EWS is working, I can retrieve the contacts:

    [DBG]: PS C:\WINDOWS\system32>> $Item
    FileAs                       : x
    FileAsMapping                : CompanySurnameCommaGivenName
    DisplayName                  : x
    GivenName                    : x
    Initials                     : x
    MiddleName                   : 
    NickName                     : 
    CompleteName                 : Microsoft.Exchange.WebServices.Data.CompleteName
    CompanyName                  : x
    EmailAddresses               : Microsoft.Exchange.WebServices.Data.EmailAddressDictionary
    PhysicalAddresses            : Microsoft.Exchange.WebServices.Data.PhysicalAddressDictionary
    PhoneNumbers                 : Microsoft.Exchange.WebServices.Data.PhoneNumberDictionary

    When I update FileAs or DisplayName with $Item.Update($EnumAlwaysOverwrite) I have no issues --> the contact is updated.

    The problem is when I try to update a Microsoft.Exchange.WebServices.Data.X-object. For ExampleEmailAddressDictionary. I can retrieve the values: 

    [DBG]: PS C:\WINDOWS\system32>> $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1]
    Name        : x
    Address     : x
    RoutingType : SMTP
    MailboxType : Contact
    Id          : 

    I then update for example "Name" with the following code:

    $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].Name = "test"
    [DBG]: PS C:\WINDOWS\system32>> $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1]
    Name        : test
    Address     : x
    RoutingType : SMTP
    MailboxType : Contact
    Id          : 

    But if I update the Item, I get an error:

    [DBG]: PS C:\WINDOWS\system32>> $Item.Update($alwaysOverwrite)
    Exception calling "Update" with "1" argument(s): "Mailbox is invalid. Verify the specified Mailbox property."
    At line:1 char:1
    + $Item.Update($alwaysOverwrite)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ServiceResponseException

    Error With Trace Enabled:

              <m:UpdateItemResponseMessage ResponseClass="Error">
                <m:MessageText>Mailbox is invalid. Verify the specified Mailbox property.</m:MessageText>
                  <t:IndexedFieldURI FieldURI="contacts:EmailAddress" FieldIndex="EmailAddress1" />
                  <t:Value Name="Property">MailboxType</t:Value>
                  <t:Value Name="Value">Contact</t:Value>
                <m:Items />

    Does anybody have an idea where it goes wrong or what i'm doing wrong?

    Many thanks.



    • Moved by Allen_WangJF Tuesday, April 17, 2018 3:52 AM Move to proper forum
    Monday, April 16, 2018 12:07 PM


All replies

  • Hi Arne,

    Welcome to Exchange Online forum.

    From your description, I notice your question is more related to EWS on Exchange Online, thus I will move this thread to Exchange Development forum which is staffed by more experts specializing in this kind of problems. For your convenience:

    The reason why we recommend posting appropriately is you will get the most qualified pool of respondents, and other partners who read the forums regularly can either share their knowledge or learn from your interaction with us. Thank you for your understanding.

    Best Regards,
    Allen Wang

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.

    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Tuesday, April 17, 2018 3:52 AM
  • You need to look at the Trace for the POST that is being sent to the server the error is telling us that there is something wrong with the element values. If this Email Address is in the Global Address List then the address should resolve back to the EX Address and name so it maybe what is going wrong. What I would suggest is you try using the Extended property definition as a work around to which should work eg

    instead of 

    $Item.EmailAddresses[[Microsoft.Exchange.WebServices.Data.EmailAddressKey]::EmailAddress1].Name = "test"

    you should use

    $Email1DisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8080,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
    $Email1OriginalDisplayName  = New-Object Microsoft.Exchange.WebServices.Data.ExtendedPropertyDefinition([Microsoft.Exchange.WebServices.Data.DefaultExtendedPropertySet]::Address,0x8084,[Microsoft.Exchange.WebServices.Data.MapiPropertyType]::String); 
    Item.SetExtendedProperty($Email1OriginalDisplayName  ,"NewName")

    Wednesday, April 18, 2018 12:35 AM
  • Hi Glen

    Thank you for response. I have solved the issue:

    The problem is with the mailboxtype. When you retrieve them, it has mailboxtype "Contact", but when you need to update them, it needs to be mailboxtype OneOff.


    I've added following line:


    And then I can update the contact.

    Thank you.



    • Marked as answer by Steini46 Wednesday, April 18, 2018 9:11 AM
    Wednesday, April 18, 2018 9:11 AM