question

VoglMartin-3487 avatar image
0 Votes"
VoglMartin-3487 asked GlenScales-6756 commented

Create/Update personal contacts with MS Graph Powershell SDK

Hello,


my goal is to sync active directory users to users personal outlook contacts. I try it and it seems to be very easy but after a several tries I mentioned that the "Display as" field wasn't filled correctly.

It always filled out with the Surname and the Givenname instead of what I want to. (Givenname Surname + mailaddress)


What I found out is that the field is only filled out incorrectly for users with a Exchange Online license.

The field is filled in correctly for users who do not have a license and I really don't know why? Can anyone explane me why?

 $anzeigenals=$displayName + " (" + $EmailAddresses + ")"
 $MAIL= @{Address = $EmailAddresses; Name = $anzeigenals}
    
 New-MgUserContact -UserId $graphuser.Id -BusinessPhones $BusinessPhones -CompanyName $CompanyName -Department $department -DisplayName $displayName -FileAs $FileAs -GivenName $GivenName -JobTitle $Jobtitle -Initials $Initials -Manager $Manager -MobilePhone $MobilePhone -OfficeLocation $OfficeLocation -Surname $Surename -EmailAddresses $mail -BusinessAddress $Anschrift -PersonalNotes $personalnotes
windows-server-powershelloffice-outlook-itpromicrosoft-graph-sdkmicrosoft-graph-contacts
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

Just to be clear, you're asking about the value in the variable $anzeigenals. Is that correct?

If so, you're using another variable $displayname to create the value stored in the $anzeigenals variable. However, only you know the contents of $displayname! How to you create the value stored in $displayname?

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

GlenScales-6756 avatar image
0 Votes"
GlenScales-6756 answered

What I found out is that the field is only filled out incorrectly for users with a Exchange Online license.

Why this is happening is because if the Address is in the GAL the contact will store the EX Address of the directory object rather then the SMTP address your trying to pass in (this is the same behaviour as Outlook or OWA) the resolution happens at the time the contact is created and there is some other business logic that happens on the backend that sets other underlying extended properties to ensure you get a valid contact. You can override the behaviour but it requires that you instead set all 5 Extended properties eg you need to convert something like https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2b375c56-bee1-4d88-b638-f95649ef964a/use-ews-create-a-contact-which-has-a-same-email-address-in-gal-it-will-show-up-with-x500-formatting?forum=exchangesvrdevelopment . I think with the Graph SDK you will need to use Update-MgUserContact after you create the contact along with SingleValueExtendedProperties to set those props.





5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VoglMartin-3487 avatar image
0 Votes"
VoglMartin-3487 answered GlenScales-6756 commented

@RichMatheisen-8856: The value was created with get-aduser....but thats not the problem. The value stored in $anzeigenals is correct.

@GelnScales-6756: I think you are right. So i created the SingleValueExtendedProperties with the Graph Explorer to check if it works as you said. (I want to do that with Powershell later) Unfortunately it didn't work that way. It creates a new Contact, but now the EmailAddresses and the Display as field are empty. So i checked with the MAPI Editor (MFCMapi.exe) if the extended properties were set. And I saw, yes they are not empty and the correct values are in there.
Maybe you ore anyone else have an idea what's wrong?

HTTPMethod: POST

 {
     "givenName": "Test",
     "surname": "Contact",
     "singleValueExtendedProperties": [
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Name PidLidEmail1DisplayName",
             "value": "Testi Contacti"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Name PidLidEmail1AddressType",
             "value": "SMTP"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Name PidLidEmail1EmailAddress",
             "value": "Test.Contact@test.com"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Name PidLidEmail1OriginalDisplayName",
             "value": "Test.Contact@test.com"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Name PidLidEmail1OriginalEntryId",
             "value": "00000000812B1FA4BEA310199D6E00DD010F540200000190"
         }
     ]
        
 }

151861-23-11-2021-13-10-46.png


151779-23-11-2021-13-12-13.png



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


All your property definitions as well as the oneoffEntryId your trying to use isn't correct you need something like

 {
     "givenName": "Dave",
     "surname": "Dobbin",
     "singleValueExtendedProperties": [
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Id 0x8080 ",
             "value": "Testi Contacti"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Id 0x8082",
             "value": "SMTP"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Id 0x8083",
             "value": "Test.Contact@test.com"
         },
         {
             "id": "String {00062004-0000-0000-C000-000000000046} Id 0x8084",
             "value": "Test.Contact@test.com"
         },
         {
             "id": "Binary {00062004-0000-0000-C000-000000000046} Id 0x8085",
             "value": "AAAAAIErH6S+oxAZnW4A3QEPVAIAAAGAVABlAHMAdABpACAAQwBvAG4AdABhAGMAdABpAAAAUwBNAFQAUAAAAFQAZQBzAHQALgBDAG8AbgB0AGEAYwB0AEAAdABlAHMAdAAuAGMAbwBtAAAA"
         }
     ]
 }

which seems to work okay

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

Hi there,

In the request body, supply the values for relevant fields that should be updated. Existing properties that are not included in the request body will maintain their previous values or be recalculated based on changes to other property values. For best performance you shouldn't include existing values that haven't changed.



--If the reply is helpful, please Upvote and Accept it as an answer--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

VoglMartin-3487 avatar image
0 Votes"
VoglMartin-3487 answered

@LimitlessTechnology-2700:
I can't understand you what would you tell me with your answer? I didn't update a contact, I create a contact and as I understand GlenScales (and his Link), the E-Mail and Display as field should filled out automatically.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.