Create/Update personal contacts with MS Graph Powershell SDK

VoglMartin-3487 6 Reputation points
2021-11-22T13:03:04.897+00:00

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
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,587 questions
Outlook Management
Outlook Management
Outlook: A family of Microsoft email and calendar products.Management: The act or process of organizing, handling, directing or controlling something.
4,886 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2021-11-22T16:05:21.643+00:00

    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?

    0 comments No comments

  2. Glen Scales 4,431 Reputation points
    2021-11-22T23:21:37.623+00:00

    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.

    0 comments No comments

  3. VoglMartin-3487 6 Reputation points
    2021-11-23T12:16:55.717+00:00

    @Rich Matheisen : 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


  4. Limitless Technology 39,351 Reputation points
    2021-11-24T10:33:59.613+00:00

    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--

    0 comments No comments

  5. VoglMartin-3487 6 Reputation points
    2021-11-25T07:15:19.353+00:00

    @Limitless Technology :
    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.

    0 comments No comments