Script repository

Create Microsoft 365 contact based on AD contact

Updated on: Jan 18, 2026, Views: 6600

Microsoft 365

The script creates a Microsoft 365 contact based on an existing Active Directory contact. To execute the script, create a business rule, custom command or scheduled task configured for the Contact object type.

# Connect to Exchange Online.
$Context.CloudServices.ConnectExchangeOnline()

# Create contact
try
{
    New-MailContact -Name "%name%" -ExternalEmailAddress "%mail%" -DisplayName "%displayName%" -FirstName "%firstname%" -LastName "%lastname%" -ErrorAction Stop
}
catch
{
    $Context.LogMessage("An error occurred when creating a contact. Error: " + $_.Exception.Message, "Warning")
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.