ContactSync automates the synchronization of Microsoft 365 users as Exchange contacts for members of a specified security group. This creates a complete, up-to-date company directory for designated users without manual maintenance.
- Automated contact synchronization - Creates and maintains contacts for all licensed users
- Organization-specific directories - Define which users serve as contacts for different groups
- Smart updates - Updates existing contacts when user information changes
- Cleanup handling - Removes contacts for deprovisioned users
- Secure authentication - Uses Azure Automation Managed Identity (no stored credentials)
- Performance optimized - Batch operations with intelligent fallback and throttling handling
- Microsoft 365 tenant with Exchange Online
- Azure Automation account
- Security group containing users who should receive the contacts
- Navigate to your Azure Automation account
- Select "Identity" from the sidebar
- Under "System assigned" tab, switch the Status to "On" and click "Save"
- Copy the Object ID - you'll need this for permissions
- Run the
utilities/Add-GraphPermissions.ps1script from a local machine with global admin permissions:.\Add-GraphPermissions.ps1 -AutomationMSI_ID "<Your-Automation-Account-MSI-Object-ID>"
- Create a security group in Microsoft 365 containing users who should receive contacts
- Note the Object ID of the group
- Import
ContactSync.ps1as a PowerShell runbook in your Automation account - Configure the required parameter
TargetGroupIdwith your security group Object ID - Publish the runbook
- Create a schedule to run ContactSync.ps1 at your desired frequency (daily recommended)
- Link the schedule to the runbook with the
TargetGroupIdparameter
| Parameter | Type | Default | Description |
|---|---|---|---|
TargetGroupId |
string | Required | The Microsoft 365 group ID containing users who should receive the contacts |
SourceGroupId |
string | "" | The Microsoft 365 group ID containing users who should be synchronized as contacts. If not specified, all licensed users in the tenant will be used. |
ExclusionListVariableName |
string | "ExclusionList" | The name of the Automation variable containing users to exclude (line-separated list) |
RemoveDeletedContacts |
bool | true | Whether to remove contacts that no longer exist in the source |
UpdateExistingContacts |
bool | true | Whether to update existing contacts with current information |
IncludeExternalContacts |
bool | true | Whether to include cloud-only users in the contact synchronization |
MaxConcurrentUsers |
int | 5 | Maximum number of concurrent users to process |
UseBatchOperations |
bool | true | Whether to attempt using batch operations (will fall back if needed) |
Advanced Feature: Configure separate contact directories for different organizations within the same tenant.
Create separate schedules for each organization:
Organization A:
TargetGroupId = "12345678-1234-1234-1234-123456789abc" # OrgA-Users group ID
SourceGroupId = "12345678-1234-1234-1234-123456789abc" # Same group - OrgA users get OrgA contactsOrganization B:
TargetGroupId = "87654321-4321-4321-4321-cba987654321" # OrgB-Users group ID
SourceGroupId = "87654321-4321-4321-4321-cba987654321" # Same group - OrgB users get OrgB contactsResult: Users in each organization only see contacts from their own organization.
ContactSync uses your Azure Automation account's Managed Identity to securely access the Microsoft Graph API and:
- Authenticates using Managed Identity (no stored credentials required)
- Retrieves source users (from SourceGroupId or all licensed users) and target users (who receive contacts)
- Synchronizes contacts by creating new ones, updating existing ones, and removing obsolete ones
- Optimizes performance with batch operations and intelligent throttling
- Authentication failures: Verify Managed Identity has required Graph API permissions
- Missing contacts: Check exclusion list and user license status
- Performance issues: Adjust the
MaxConcurrentUsersparameter
- In Azure Automation, go to the Jobs section
- Select the most recent job run
- View the Output tab for detailed logs
Additional maintenance scripts are available in the utilities/ folder:
ContactCleanup.ps1- Removes duplicate contacts and specific categoriesDeleteContactFolder.ps1- Deletes specific contact folders (e.g., "Administrator")ContactDiagnostic.ps1- Analyzes contact data for troubleshootingAdd-GraphPermissions.ps1- Assigns Graph API permissions to Managed Identity
These are typically used for one-time cleanup operations or diagnostics.