What is the UserID required by Get-MgUserContact?

JayCarper-5747 216 Reputation points
2024-07-01T21:34:31.9933333+00:00

According to the documentation, Get-MgUserContact requires either a UPN or a UserId in the -UserId field. However, mail contacts don't have UPNs, and the documentation doesn't define what a mail contact's UserID is. I've tried email address, display name, alias, Identity (from Get-MailContact), ExchangeObjectId, and Guid (same as ExchangeObjectId). Everything returns "Get-MgUserContact : The requested user '<attempted UserID value>' is invalid."

Get-MgUserContact -UserId ??????

Microsoft Exchange Online
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,206 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,260 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. akinbade abiola 6,575 Reputation points
    2024-07-01T23:51:33.8+00:00

    Hello JayCarper-5747,

    Thanks for your question.

    The user Id is the unique identifier (ObjectId) from Entra ID.

    To find a user's object ID, use the following steps:

    1. Sign in to the Azure portal.
    2. Select Microsoft Entra ID from the menu.
    3. Locate the Manage section on the menu and then select Users.
    4. On the Users page, enter the user's name in the Search box.
    5. Select the user's name where it appears on the list.
    6. Locate the Basic info section on the user's Profile page. The Object ID that is displayed is the user's unique object ID.

    The above is documented here: https://learn.microsoft.com/en-us/partner-center/account-settings/find-ids-and-domain-names

    You can mark it 'Accept Answer' and 'Upvote' if this helped you

    Regards,

    Abiola

    0 comments No comments

  2. Vasil Michev 99,106 Reputation points MVP
    2024-07-02T06:24:43.5266667+00:00

    You are correct that contact objects do not have a UPN. However, the cmdlet above does not run against a specific contact object, instead it lists all the personal contacts stored in a given user's mailbox. In effect, the UserId value you are providing is for the owner of said mailbox, which does have an UPN.

    In other words, this cmdlet will return your personal contacts:

    Get-MgUserContact -UserId jay.carper@domain.com
    
    
    0 comments No comments