Can't register a Hybrid Agent in Exchange Server

Symptoms

When you use the Hybrid Configuration wizard (HCW) to set up a Microsoft Hybrid Agent, you see the following registration error in the HCW for the installed Hybrid Agent.

Screenshot of a Hybrid Agent registration error in the HCW.

You also receive the following error entries in the HCW log:

10333 \[Client=UX, fn=SendAsync, Thread=\<ID\>\] Results=NotFound {"error":
{"code":"Application_NotFound", "message":"Application '\<application GUID\>' not found or
OnPremisesPublishing is not enabled for your tenant."
10333 \[Client=UX, fn=SendAsync, Thread=\<ID\>\] Results=BadRequest {"error":
{"code": "InternalUrl_Duplicate", "message":"Internal url '\<application URL\>' is invalid
since it is already in use."

Cause

The errors occur if the internal URL that's used by the Hybrid Agent application is already in use within your organization. More specifically:

Cause 1

The same internal URL is used by an existing enterprise on-premises app that uses Microsoft Entra application proxy.

Cause 2

The same internal URL is used by a previously installed, orphaned Hybrid Agent application that's not fully registered. An orphaned Hybrid Agent application can be caused by a failed Hybrid Agent installation or uninstallation.

Resolution

Use the appropriate resolution, depending on the cause.

Resolution for Cause 1

Choose one of the following options:

Note

Azure AD and MSOnline PowerShell modules are deprecated as of March 30, 2024. To learn more, read the deprecation update. After this date, support for these modules are limited to migration assistance to Microsoft Graph PowerShell SDK and security fixes. The deprecated modules will continue to function through March, 30 2025.

We recommend migrating to Microsoft Graph PowerShell to interact with Microsoft Entra ID (formerly Azure AD). For common migration questions, refer to the Migration FAQ. Note: Versions 1.0.x of MSOnline may experience disruption after June 30, 2024.

Resolution for Cause 2

Remove the previously installed, orphaned Hybrid Agent application. To do this, follow these steps:

  1. Get the application GUID of the previous Hybrid Agent application. You can find this GUID by searching the HCW log for the following entry:

    10386 [Client=UX, Thread=<ID>] Previous Connector Application Name found: <application GUID>

    The entry might resemble the following example:

    10386 [Client=UX, Thread=20] Previous Connector Application Name found: 8fc44b37-bf0d-45bf-8254-d4d033d93a6e

  2. Remove the previous Hybrid Agent application. To do this, follow these steps:

    1. Load the HybridManagement PowerShell module:

      1. Install the Microsoft PackageManagement PowerShell module.

      2. Install the Microsoft Azure PowerShell module.

      3. Download the latest version of the Microsoft HybridManagement.psm1 PowerShell module to a server in your Exchange organization.

      4. In the folder that contains the HybridManagement module, run the following PowerShell command as an administrator:

        Import-Module .\HybridManagement.psm1
        
    2. Pass the application GUID that you found in step 1 to the Remove-HybridApplication cmdlet:

      Remove-HybridApplication -AppId <application GUID> -Credential (Get-Credential)
      

      Or, if you have MFA enabled, run:

      Remove-HybridApplication -AppId <application GUID> -UserPrincipalName <tenant admin UPN>
      

      When you're prompted for credentials, enter your Microsoft 365 or Office 365 Global Administrator credentials.

  3. Re-run the HCW in classic mode to unregister the Application Proxy service in Microsoft Entra ID.

  4. Go to Programs and Features in Control Panel, verify that Microsoft Hybrid Service isn't installed. If it is, re-run step 2 to remove the Hybrid Agent application.

  5. Re-run the HCW in modern mode.

    Note

    When you're prompted to choose a hybrid topology, select Exchange Modern Hybrid Topology.

If the Hybrid Agent application isn't successfully removed, use one of the following options:

  • Run the following Remove-AzureADApplicationProxyApplication command:

    Remove-AzureADApplicationProxyApplication -ObjectId <application GUID> -RemoveADApplication $true
    
  • Run the following command to get the application GUID, and then run the Remove-AzureADApplicationProxyApplication command to remove the application:

    Get-AzureADServicePrincipal | where {$_.Tags -Contains "WindowsAzureActiveDirectoryOnPremApp"} | fl AppId, DisplayName
    

If you still can't remove the Hybrid Agent application, contact Microsoft Support.