ANAVEM
Languagefr
How to Block Soft and Hard Match in Microsoft Entra ID for Enhanced Security

How to Block Soft and Hard Match in Microsoft Entra ID for Enhanced Security

Disable soft and hard matching capabilities in Microsoft Entra ID using PowerShell to prevent unauthorized cloud object takeover and enhance tenant security.

April 10, 2026 12 min
hardentra-id 7 steps 12 min

Why Should You Block Soft and Hard Matching in Microsoft Entra ID?

Microsoft Entra ID's soft and hard matching features, while designed to simplify object synchronization during migrations, create significant security vulnerabilities that can be exploited by attackers to take over cloud identities. Understanding and properly configuring these features is crucial for maintaining a secure hybrid identity environment.

What Are the Security Risks of Enabled Matching?

Soft matching automatically links on-premises and cloud objects based on userPrincipalName or primary SMTP address. This seemingly convenient feature can be exploited when an attacker gains access to your on-premises Active Directory and creates objects with matching attributes to existing cloud users. Hard matching, which uses the ImmutableID (source anchor), provides more precision but can still be manipulated if an attacker compromises your on-premises environment and can control source anchor values.

The attack scenario is straightforward: an attacker with on-premises AD access creates a user account with a userPrincipalName or source anchor that matches an existing cloud object, particularly high-privilege accounts. During the next Entra Connect synchronization cycle, the matching logic links these objects, effectively giving the attacker control over the cloud identity and its associated permissions.

How Does Microsoft Recommend Securing These Features?

Microsoft's current security guidance strongly recommends disabling both soft and hard matching by default and only enabling them during specific migration windows when absolutely necessary. This approach follows the principle of least privilege and significantly reduces the attack surface for identity takeover attempts. The blocking features should be considered a fundamental security hardening step for any organization using Entra Connect for hybrid identity synchronization.

Implementation Guide

Full Procedure

01

Install and Connect to Microsoft Entra PowerShell Module

First, install the Microsoft.Entra PowerShell module, which is Microsoft's current recommended approach for managing directory synchronization features. This module replaces the legacy MSOnline module.

Install-Module Microsoft.Entra -Repository PSGallery -Force -AllowClobber

Import the module and connect to your Entra ID tenant with the required permissions:

Import-Module Microsoft.Entra
Connect-Entra -Scopes 'OnPremDirectorySynchronization.ReadWrite.All'

When prompted, authenticate with your Global Administrator or Directory Synchronization Administrator credentials. The connection will establish a session with your tenant.

Pro tip: Use Get-EntraContext to verify your connection and see which tenant you're connected to before making changes.

Verification: Run Get-EntraContext to confirm you're connected to the correct tenant. You should see your tenant ID and authentication details displayed.

02

Check Current Soft and Hard Match Status

Before making any changes, examine the current state of your directory synchronization features. This baseline check helps you understand what's currently enabled and provides a reference point.

Get-EntraDirSyncFeature

This command displays all directory synchronization features and their current enabled/disabled status. Look specifically for these two features:

  • BlockSoftMatch - Controls soft matching based on userPrincipalName or primary SMTP address
  • BlockCloudObjectTakeoverThroughHardMatch - Controls hard matching via source anchor (ImmutableID)

The output will show True if the blocking is enabled (secure) or False if matching is allowed (potential security risk).

Warning: If both features show False, your tenant is vulnerable to object takeover attacks. Proceed with the blocking steps immediately.

Verification: The command output should display a table with feature names and their current status. Document these current settings before proceeding.

03

Block Soft Matching to Prevent UPN-Based Takeovers

Soft matching automatically links on-premises and cloud objects based on userPrincipalName or primary SMTP address. While convenient for migrations, it creates a significant security vulnerability where attackers can potentially take over cloud objects.

Get your tenant ID and block soft matching:

$tenantID = (Get-EntraContext).TenantId
Set-EntraDirSyncFeature -Features 'BlockSoftMatch' -Enable $true -TenantId $tenantID -Force

This command immediately disables soft matching across your entire tenant. The -Force parameter bypasses confirmation prompts, making it suitable for automation scripts.

Soft matching works by comparing these attributes between on-premises and cloud objects:

  • userPrincipalName (primary matching attribute)
  • Primary SMTP address from proxyAddresses
  • Mail attribute (if present)

When blocked, Entra Connect will only establish object relationships through explicit hard matching or during initial synchronization.

Pro tip: If you need to perform a one-time migration, you can temporarily disable this block, complete your migration, then immediately re-enable it for ongoing security.

Verification: Run Get-EntraDirSyncFeature again and confirm that BlockSoftMatch now shows True.

04

Block Hard Matching to Prevent Source Anchor Takeovers

Hard matching uses the ImmutableID (source anchor) to link objects. While more precise than soft matching, it can still be exploited if an attacker gains access to on-premises Active Directory and can manipulate source anchor values.

Block cloud object takeover through hard matching:

$tenantID = (Get-EntraContext).TenantId
Set-EntraDirSyncFeature -Features 'BlockCloudObjectTakeoverThroughHardMatch' -Enable $true -TenantId $tenantID -Force

This protection prevents scenarios where:

  • An attacker compromises on-premises AD
  • They create a new user with a source anchor matching an existing cloud object
  • Entra Connect would normally link these objects, giving the attacker control over the cloud identity

With this block enabled, Entra Connect will reject synchronization attempts that would result in unauthorized object takeover through source anchor manipulation.

The enforcement logic verifies on-premises mapping attributes before allowing any source-of-authority remapping, effectively blocking suspicious remapping attempts.

Warning: This setting may impact legitimate migration scenarios where you need to link existing cloud objects to new on-premises objects. Plan your migrations carefully and temporarily disable this block only when necessary.

Verification: Run Get-EntraDirSyncFeature and confirm that BlockCloudObjectTakeoverThroughHardMatch shows True.

05

Verify Blocking Configuration and Test Sync Behavior

After enabling both blocking features, perform a comprehensive verification to ensure your security configuration is active and functioning correctly.

Check the final status of all directory synchronization features:

Get-EntraDirSyncFeature | Where-Object {$_.FeatureName -like '*Block*'} | Format-Table FeatureName, Enabled -AutoSize

This filtered view shows only the blocking-related features for easy verification. Both should display True in the Enabled column.

If you have Entra Connect running, trigger a manual synchronization to test the new behavior:

# Run this on your Entra Connect server
Start-ADSyncSyncCycle -PolicyType Delta

Monitor the synchronization logs for any changes in behavior. With blocking enabled, you should see:

  • No automatic soft matching of objects based on UPN or email
  • Rejection of hard match attempts that would result in object takeover
  • Clear error messages if legitimate matching attempts are blocked
Pro tip: Set up monitoring alerts for Entra Connect synchronization errors. With blocking enabled, legitimate migration attempts will generate specific error codes that you can use to identify when temporary unblocking might be needed.

Verification: Check Entra Connect synchronization reports and ensure no unexpected object linking occurs during the next sync cycle.

06

Configure Temporary Unblocking for Planned Migrations

Microsoft recommends keeping blocking enabled by default and only disabling it during specific migration windows. Here's how to safely manage temporary unblocking for legitimate business needs.

Create a script for temporary unblocking during migrations:

# Save current blocking status
$currentSoftMatch = (Get-EntraDirSyncFeature | Where-Object {$_.FeatureName -eq 'BlockSoftMatch'}).Enabled
$currentHardMatch = (Get-EntraDirSyncFeature | Where-Object {$_.FeatureName -eq 'BlockCloudObjectTakeoverThroughHardMatch'}).Enabled

Write-Host "Current BlockSoftMatch: $currentSoftMatch"
Write-Host "Current BlockCloudObjectTakeoverThroughHardMatch: $currentHardMatch"

# Temporarily disable for migration (use with extreme caution)
$tenantID = (Get-EntraContext).TenantId
Set-EntraDirSyncFeature -Features 'BlockSoftMatch' -Enable $false -TenantId $tenantID -Force
Set-EntraDirSyncFeature -Features 'BlockCloudObjectTakeoverThroughHardMatch' -Enable $false -TenantId $tenantID -Force

Write-Host "Blocking temporarily disabled for migration. Re-enable immediately after completion!"

After completing your migration tasks, immediately re-enable the blocking:

# Re-enable blocking after migration
$tenantID = (Get-EntraContext).TenantId
Set-EntraDirSyncFeature -Features 'BlockSoftMatch' -Enable $true -TenantId $tenantID -Force
Set-EntraDirSyncFeature -Features 'BlockCloudObjectTakeoverThroughHardMatch' -Enable $true -TenantId $tenantID -Force

Write-Host "Security blocking re-enabled successfully."
Warning: Never leave blocking disabled longer than absolutely necessary. Each minute of disabled blocking increases your attack surface. Consider implementing automated re-enabling after a specific time window.

Verification: Always run Get-EntraDirSyncFeature after re-enabling to confirm both blocking features are active again.

07

Implement Monitoring and Compliance Verification

Establish ongoing monitoring to ensure your blocking configuration remains secure and compliant with Microsoft's security recommendations.

Create a monitoring script to regularly check blocking status:

# Monitoring script for blocking status
function Test-EntraMatchingBlocks {
    try {
        Connect-Entra -Scopes 'OnPremDirectorySynchronization.ReadWrite.All' -ErrorAction Stop
        
        $features = Get-EntraDirSyncFeature
        $softMatchBlocked = ($features | Where-Object {$_.FeatureName -eq 'BlockSoftMatch'}).Enabled
        $hardMatchBlocked = ($features | Where-Object {$_.FeatureName -eq 'BlockCloudObjectTakeoverThroughHardMatch'}).Enabled
        
        $result = @{
            'SoftMatchBlocked' = $softMatchBlocked
            'HardMatchBlocked' = $hardMatchBlocked
            'ComplianceStatus' = ($softMatchBlocked -and $hardMatchBlocked)
            'CheckDate' = Get-Date
        }
        
        if ($result.ComplianceStatus) {
            Write-Host "✓ COMPLIANT: Both soft and hard matching are blocked" -ForegroundColor Green
        } else {
            Write-Host "✗ NON-COMPLIANT: Matching blocks are not properly configured" -ForegroundColor Red
        }
        
        return $result
    }
    catch {
        Write-Error "Failed to check blocking status: $($_.Exception.Message)"
    }
}

# Run the compliance check
Test-EntraMatchingBlocks

For enterprise environments, consider implementing this check as part of your security compliance framework. The Maester security testing framework includes test MT.1073 specifically for verifying soft and hard match blocking.

Set up automated alerts for configuration drift:

# Example: Schedule this as a daily task
$complianceCheck = Test-EntraMatchingBlocks
if (-not $complianceCheck.ComplianceStatus) {
    # Send alert to security team
    Send-MailMessage -To "security@company.com" -Subject "Entra ID Matching Blocks Non-Compliant" -Body "Soft/Hard matching blocks are not properly configured. Immediate attention required."
}
Pro tip: Integrate this monitoring into your existing security information and event management (SIEM) system to correlate with other security events and maintain a comprehensive security posture.

Verification: Run the monitoring script and confirm it correctly identifies the current blocking status. Test the alert mechanism to ensure notifications work properly.

Frequently Asked Questions

What happens if I block soft and hard matching during an active migration?+
Blocking these features during an active migration will prevent automatic object linking and may cause synchronization errors. Microsoft recommends completing migrations first, then enabling blocks. If you must migrate with blocks enabled, you'll need to manually configure object relationships using PowerShell and the ImmutableID attribute before synchronization.
Can I selectively block matching for specific users or groups instead of the entire tenant?+
No, the BlockSoftMatch and BlockCloudObjectTakeoverThroughHardMatch features are tenant-wide settings that cannot be applied selectively. They affect all synchronization operations across your entire Entra ID tenant. For granular control, you must manage object relationships manually through PowerShell scripting and careful ImmutableID management.
How do I know if an attacker has already exploited soft or hard matching in my environment?+
Review your Entra Connect synchronization logs for unexpected object linking events, especially for privileged accounts. Check for recently synchronized objects that weren't part of planned migrations. Use the Get-EntraDirSyncFeature command to see when blocking was last modified, and audit your on-premises AD for suspicious user accounts with UPNs or attributes matching cloud objects.
Will blocking soft and hard matching affect existing synchronized objects?+
No, blocking these features only prevents new automatic object linking during future synchronization cycles. Existing synchronized objects that were previously linked through soft or hard matching will continue to function normally. The blocks only apply to new synchronization attempts that would create object relationships.
What's the difference between using Microsoft.Entra module versus the legacy MSOnline module for blocking?+
The Microsoft.Entra module is Microsoft's current recommended approach, offering better security, modern authentication, and ongoing support. The legacy MSOnline module still works but is deprecated and may not receive security updates. The Microsoft.Entra module uses more granular permission scopes and provides better integration with modern PowerShell environments and automation frameworks.

Discussion

Share your thoughts and insights

Sign in to join the discussion