0
votes

I'm trying to see if there is a way to sort contacts by Surname in EWS after they have already been imported into the contacts folder.

I had a member from this site assist me with some code to import a list of contacts using the ThreadJob Module. As an overview of what my code looks lie, you can please refer to this link: Contacts import using runspacepools

The modified code from the link above works great and it imports the contacts in half the time (originally took between 5-6 mins and afterwards between 2-3 mins). The new issue I am facing now is that since the import runs in different thread jobs it imports contacts out of order, so I'm curious if there is a easy way to tell Exchange to resort them by SurName? Any thoughts?

I am open to using EWS/EWS API/ Graph API, or any other method you can think of. I would need to sort this for all users mailboxes.

Thank you!

1

1 Answers

0
votes

It looks like your not setting the FileAs property in you code which means you will just get the default FileAs order in Outlook or OWA. eg in the Graph you post should include that property eg

POST https://graph.microsoft.com/v1.0/me/contactFolders/{id}/contacts
Content-type: application/json
Content-length: 210

{
  "parentFolderId": "parentFolderId-value",
  "birthday": "datetime-value",
  "fileAs": "fileAs-value",
  "displayName": "displayName-value",
  "givenName": "givenName-value",
  "initials": "initials-value"
}

Usually you would do something like Surname,FirstName

Your question is a little confusing however because you mention EWS which doesn't sort items by default it will just return then in FIFO order so the order in which they where created. You can use OrderBy in EWS with an ItemView https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.itemview.orderby?redirectedfrom=MSDN&view=exchange-ews-api#Microsoft_Exchange_WebServices_Data_ItemView_OrderBy