Partager via


Configurer la synchronisation entre clients à l’aide de PowerShell ou de l’API Microsoft Graph

Cet article décrit les étapes clés de configuration de la synchronisation entre clients à l’aide de PowerShell Microsoft Graph ou de l’API Microsoft Graph. Une fois configuré, Microsoft Entra ID approvisionne et déprovisionne automatiquement les utilisateurs B2B dans votre locataire cible. Pour obtenir des instructions détaillées sur les étapes à l’aide du Centre d’administration Microsoft Entra, consultez Configurer la synchronisation interlocataire.

Diagramme montrant la synchronisation entre locataires entre le locataire source et le locataire cible.

Prérequis

Icône du locataire source.
Locataire source

Icône du locataire cible.
Locataire cible

Étape 1 : connectez-vous au locataire cible

Icône du locataire cible.
Locataire cible

  1. Démarrez PowerShell.

  2. Si nécessaire, installez le Kit de développement logiciel (SDK) PowerShell Microsoft Graph.

  3. Obtenez l’ID des locataires source et cible, puis initialisez les variables.

    $SourceTenantId = "<SourceTenantId>"
    $TargetTenantId = "<TargetTenantId>"
    
  4. Utilisez la commande Connect-MgGraph pour vous connecter au locataire cible et consentir aux autorisations requises suivantes.

    • Policy.Read.All
    • Policy.ReadWrite.CrossTenantAccess
    Connect-MgGraph -TenantId $TargetTenantId -Scopes "Policy.Read.All","Policy.ReadWrite.CrossTenantAccess"
    

Étape 2 : Activer la synchronisation des utilisateurs dans le locataire cible

Icône du locataire cible.
Locataire cible

  1. Dans le locataire cible, utilisez la commande New-MgPolicyCrossTenantAccessPolicyPartner pour créer une configuration de partenaire dans une stratégie d’accès entre le locataire cible et le locataire source. Utilisez l’ID de locataire source dans la demande.

    Si vous obtenez l’erreur New-MgPolicyCrossTenantAccessPolicyPartner_Create: Another object with the same value for property tenantId already exists, vous disposez peut-être déjà d’une configuration existante. Pour plus d’informations, consultez Symptôme – erreur New-MgPolicyCrossTenantAccessPolicyPartner_Create.

    $Params = @{
        TenantId = $SourceTenantId
    }
    New-MgPolicyCrossTenantAccessPolicyPartner -BodyParameter $Params | Format-List
    
    AutomaticUserConsentSettings : Microsoft.Graph.PowerShell.Models.MicrosoftGraphInboundOutboundPolicyConfiguration
    B2BCollaborationInbound      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    B2BCollaborationOutbound     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    B2BDirectConnectInbound      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    B2BDirectConnectOutbound     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    IdentitySynchronization      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantIdentitySyncPolicyPartner
    InboundTrust                 : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyInboundTrust
    IsServiceProvider            :
    TenantId                     : <SourceTenantId>
    TenantRestrictions           : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyTenantRestrictions
    AdditionalProperties         : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#policies/crossTenantAccessPolicy/partners/$entity],
                                   [crossCloudMeetingConfiguration,
                                   System.Collections.Generic.Dictionary`2[System.String,System.Object]], [protectedContentSharing,
                                   System.Collections.Generic.Dictionary`2[System.String,System.Object]]}
    
  2. Utilisez la commande Invoke-MgGraphRequest pour activer la synchronisation utilisateur dans le locataire cible.

    Si vous obtenez une Request_MultipleObjectsWithSameKeyValue erreur, vous disposez peut-être déjà d’une stratégie existante. Pour plus d’informations, consultez Symptôme : erreur Request_MultipleObjectsWithSameKeyValue.

    $Params = @{
        userSyncInbound = @{
            isSyncAllowed = $true
        }
    }
    Invoke-MgGraphRequest -Method PUT -Uri "https://graph.microsoft.com/v1.0/policies/crossTenantAccessPolicy/partners/$SourceTenantId/identitySynchronization" -Body $Params
    
  3. Utilisez la commande Get-MgPolicyCrossTenantAccessPolicyPartnerIdentitySynchronization pour vérifier que IsSyncAllowed est défini sur True.

    (Get-MgPolicyCrossTenantAccessPolicyPartnerIdentitySynchronization -CrossTenantAccessPolicyConfigurationPartnerTenantId $SourceTenantId).UserSyncInbound
    
    IsSyncAllowed
    -------------
    True
    

Étape 3 : échanger automatiquement les invitations dans le locataire cible

Icône du locataire cible.
Locataire cible

  1. Dans le locataire cible, utilisez la commande Update crossTenantAccessPolicyConfigurationPartnerUpdate-MgPolicyCrossTenantAccessPolicyPartner pour accepter automatiquement les invitations et supprimer les invites de consentement pour l’accès entrant.

    $AutomaticUserConsentSettings = @{
        "InboundAllowed"="True"
    }
    Update-MgPolicyCrossTenantAccessPolicyPartner -CrossTenantAccessPolicyConfigurationPartnerTenantId $SourceTenantId -AutomaticUserConsentSettings $AutomaticUserConsentSettings
    

Étape 4 : connectez-vous au locataire source

Icône du locataire source.
Locataire source

  1. Démarrez une instance de PowerShell.

  2. Obtenez l’ID des locataires source et cible, puis initialisez les variables.

    $SourceTenantId = "<SourceTenantId>"
    $TargetTenantId = "<TargetTenantId>"
    
  3. Utilisez la commande Connect-MgGraph pour vous connecter au locataire source et consentir aux autorisations requises suivantes.

    • Policy.Read.All
    • Policy.ReadWrite.CrossTenantAccess
    • Application.ReadWrite.All
    • Directory.ReadWrite.All
    • AuditLog.Read.All
    Connect-MgGraph -TenantId $SourceTenantId -Scopes "Policy.Read.All","Policy.ReadWrite.CrossTenantAccess","Application.ReadWrite.All","Directory.ReadWrite.All","AuditLog.Read.All"
    

Étape 5 : échangez automatiquement les invitations dans le locataire source

Icône du locataire source.
Locataire source

  1. Dans le locataire source, utilisez la commande New-MgPolicyCrossTenantAccessPolicyPartner pour créer une configuration de partenaire dans une stratégie d’accès entre le locataire source et le locataire cible. Utilisez l’ID de locataire cible dans la demande.

    Si vous obtenez l’erreur New-MgPolicyCrossTenantAccessPolicyPartner_Create: Another object with the same value for property tenantId already exists, vous disposez peut-être déjà d’une configuration existante. Pour plus d’informations, consultez Symptôme – erreur New-MgPolicyCrossTenantAccessPolicyPartner_Create.

    $Params = @{
        TenantId = $TargetTenantId
    }
    New-MgPolicyCrossTenantAccessPolicyPartner -BodyParameter $Params | Format-List
    
    AutomaticUserConsentSettings : Microsoft.Graph.PowerShell.Models.MicrosoftGraphInboundOutboundPolicyConfiguration
    B2BCollaborationInbound      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    B2BCollaborationOutbound     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    B2BDirectConnectInbound      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    B2BDirectConnectOutbound     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyB2BSetting
    IdentitySynchronization      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantIdentitySyncPolicyPartner
    InboundTrust                 : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyInboundTrust
    IsServiceProvider            :
    TenantId                     : <TargetTenantId>
    TenantRestrictions           : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCrossTenantAccessPolicyTenantRestrictions
    AdditionalProperties         : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#policies/crossTenantAccessPolicy/partners/$entity],
                                   [crossCloudMeetingConfiguration,
                                   System.Collections.Generic.Dictionary`2[System.String,System.Object]], [protectedContentSharing,
                                   System.Collections.Generic.Dictionary`2[System.String,System.Object]]}
    
    
  2. Utilisez la commande Update-MgPolicyCrossTenantAccessPolicyPartner pour échanger automatiquement des invitations et supprimer les invites de consentement pour l’accès sortant.

    $AutomaticUserConsentSettings = @{
        "OutboundAllowed"="True"
    }
    Update-MgPolicyCrossTenantAccessPolicyPartner -CrossTenantAccessPolicyConfigurationPartnerTenantId $TargetTenantId -AutomaticUserConsentSettings $AutomaticUserConsentSettings
    

Étape 6 : créez une application de configuration dans le locataire source

Icône du locataire source.
Locataire source

  1. Dans le locataire source, utilisez la commande Invoke-MgInstantiateApplicationTemplate pour ajouter une instance d’une application de configuration depuis la galerie d’applications Microsoft Entra à votre locataire.

    Invoke-MgInstantiateApplicationTemplate -ApplicationTemplateId "518e5f48-1fc8-4c48-9387-9fdf28b0dfe7" -DisplayName "Fabrikam"
    
  2. Utilisez la commande Get-MgServicePrincipal pour obtenir l’ID du principal de service.

    Get-MgServicePrincipal -Filter "DisplayName eq 'Fabrikam'" | Format-List
    
    AccountEnabled                      : True
    AddIns                              : {}
    AlternativeNames                    : {}
    AppDescription                      :
    AppDisplayName                      : Fabrikam
    AppId                               : <AppId>
    AppManagementPolicies               :
    AppOwnerOrganizationId              : <AppOwnerOrganizationId>
    AppRoleAssignedTo                   :
    AppRoleAssignmentRequired           : True
    AppRoleAssignments                  :
    AppRoles                            : {<AppRoleId>}
    ApplicationTemplateId               : 518e5f48-1fc8-4c48-9387-9fdf28b0dfe7
    ClaimsMappingPolicies               :
    CreatedObjects                      :
    CustomSecurityAttributes            : Microsoft.Graph.PowerShell.Models.MicrosoftGraphCustomSecurityAttributeValue
    DelegatedPermissionClassifications  :
    DeletedDateTime                     :
    Description                         :
    DisabledByMicrosoftStatus           :
    DisplayName                         : Fabrikam
    Endpoints                           :
    ErrorUrl                            :
    FederatedIdentityCredentials        :
    HomeRealmDiscoveryPolicies          :
    Homepage                            : https://account.activedirectory.windowsazure.com:444/applications/default.aspx?metadata=aad2aadsync|ISV9.1|primary|z
    Id                                  : <ServicePrincipalId>
    Info                                : Microsoft.Graph.PowerShell.Models.MicrosoftGraphInformationalUrl
    KeyCredentials                      : {}
    LicenseDetails                      :
    
    ...
    
  3. Initialisez une variable pour l’ID du principal de service.

    Veillez à utiliser l’ID du principal de service plutôt que l’ID d’application.

    $ServicePrincipalId = "<ServicePrincipalId>"
    
  4. Initialisez une variable pour l’ID de rôle d’application.

    $AppRoleId= "<AppRoleId>"
    

Étape 7 : testez la connexion au locataire cible

Icône du locataire source.
Locataire source

  1. Dans le locataire source, utilisez la commande Invoke-MgGraphRequest pour tester la connexion au locataire cible et valider les informations d’identification.

    $Params = @{
        "useSavedCredentials" = $false
        "templateId" = "Azure2Azure"
        "credentials" = @(
            @{
                "key" = "CompanyId"
                "value" = $TargetTenantId
            }
            @{
                "key" = "AuthenticationType"
                "value" = "SyncPolicy"
            }
        )
    }
    Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/v1.0/servicePrincipals/$ServicePrincipalId/synchronization/jobs/validateCredentials" -Body $Params
    

Étape 8 : Créer un travail d’approvisionnement dans le locataire source

Icône du locataire source.
Locataire source

Dans le locataire source, pour activer l’approvisionnement, créez un travail d’approvisionnement.

  1. Déterminez le modèle de synchronisation à utiliser, par exemple Azure2Azure.

    Un modèle a des paramètres de synchronisation préconfigurés.

  2. Dans le locataire source, utilisez la commande New-MgServicePrincipalSynchronizationJob pour créer un travail d’approvisionnement basé sur un modèle.

    New-MgServicePrincipalSynchronizationJob -ServicePrincipalId $ServicePrincipalId -TemplateId "Azure2Azure" | Format-List
    
    Id                         : <JobId>
    Schedule                   : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSynchronizationSchedule
    Schema                     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSynchronizationSchema
    Status                     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSynchronizationStatus
    SynchronizationJobSettings : {AzureIngestionAttributeOptimization, LookaheadQueryEnabled}
    TemplateId                 : Azure2Azure
    AdditionalProperties       : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('<ServicePrincipalId>')/synchro
                                 nization/jobs/$entity]}
    
  3. Initialisez une variable pour l’ID de travail.

    $JobId = "<JobId>"
    

Étape 9 : Enregistrer vos informations d’identification

Icône du locataire source.
Locataire source

  1. Dans le locataire source, utilisez la commande Invoke-MgGraphRequest pour enregistrer vos informations d’identification.

    $Params = @{
        "value" = @(
            @{
                "key" = "AuthenticationType"
                "value" = "SyncPolicy"
            }
            @{
                "key" = "CompanyId"
                "value" = $TargetTenantId
            }
        )
    }
    Invoke-MgGraphRequest -Method PUT -Uri "https://graph.microsoft.com/v1.0/servicePrincipals/$ServicePrincipalId/synchronization/secrets" -Body $Params
    

Étape 10 : affectez un utilisateur à la configuration

Icône du locataire source.
Locataire source

Pour que la synchronisation interlocataire fonctionne, au moins un utilisateur interne doit être affecté à la configuration.

  1. Dans le locataire source, utilisez la commande New-MgServicePrincipalAppRoleAssignedTo pour affecter un utilisateur interne à la configuration.

    $Params = @{
        PrincipalId = "<PrincipalId>"
        ResourceId = $ServicePrincipalId
        AppRoleId = $AppRoleId
    }
    New-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $ServicePrincipalId -BodyParameter $Params | Format-List
    
    AppRoleId            : <AppRoleId>
    CreatedDateTime      : 7/31/2023 10:27:12 PM
    DeletedDateTime      :
    Id                   : <Id>
    PrincipalDisplayName : User1
    PrincipalId          : <PrincipalId>
    PrincipalType        : User
    ResourceDisplayName  : Fabrikam
    ResourceId           : <ServicePrincipalId>
    AdditionalProperties : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#appRoleAssignments/$entity]}
    

Étape 11 : Tester l’approvisionnement à la demande

Icône du locataire source.
Locataire source

Maintenant que vous avez une configuration, vous pouvez tester l’approvisionnement à la demande avec l’un de vos utilisateurs.

  1. Dans le locataire source, utilisez la commande Get-MgServicePrincipalSynchronizationJobSchema pour obtenir l’ID de règle de schéma.

    $SynchronizationSchema = Get-MgServicePrincipalSynchronizationJobSchema -ServicePrincipalId $ServicePrincipalId -SynchronizationJobId $JobId
    $SynchronizationSchema.SynchronizationRules | Format-List
    
    ContainerFilter      : Microsoft.Graph.PowerShell.Models.MicrosoftGraphContainerFilter
    Editable             : True
    GroupFilter          : Microsoft.Graph.PowerShell.Models.MicrosoftGraphGroupFilter
    Id                   : <RuleId>
    Metadata             : {defaultSourceObjectMappings, supportsProvisionOnDemand}
    Name                 : USER_INBOUND_USER
    ObjectMappings       : {Provision Azure Active Directory Users, , , …}
    Priority             : 1
    SourceDirectoryName  : Azure Active Directory
    TargetDirectoryName  : Azure Active Directory (target tenant)
    AdditionalProperties : {}
    
  2. Initialiser une variable pour l’ID de règle.

    $RuleId = "<RuleId>"
    
  3. Dans le locataire source, utilisez la commande New-MgServicePrincipalSynchronizationJobOnDemand pour approvisionner un utilisateur de test à la demande.

    $Params = @{
        Parameters = @(
            @{
                Subjects = @(
                    @{
                        ObjectId = "<UserObjectId>"
                        ObjectTypeName = "User"
                    }
                )
                RuleId = $RuleId
            }
        )
    }
    New-MgServicePrincipalSynchronizationJobOnDemand -ServicePrincipalId $ServicePrincipalId -SynchronizationJobId $JobId -BodyParameter $Params | Format-List
    
    Key                  : Microsoft.Identity.Health.CPP.Common.DataContracts.SyncFabric.StatusInfo
    Value                : [{"provisioningSteps":[{"name":"EntryImport","type":"Import","status":"Success","description":"Retrieved User
                           'user1@fabrikam.com' from Azure Active Directory","timestamp":"2023-07-31T22:31:15.9116590Z","details":{"objectId":
                           "<UserObjectId>","accountEnabled":"True","displayName":"User1","mailNickname":"user1","userPrincipalName":"use
                           ...
    AdditionalProperties : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.stringKeyStringValuePair]}
    

Étape 12 : Démarrer le travail d’approvisionnement

Icône du locataire source.
Locataire source

  1. Maintenant que le travail d’approvisionnement est configuré, dans le locataire source, utilisez la commande Start-MgServicePrincipalSynchronizationJob pour démarrer le travail d’approvisionnement.

    Start-MgServicePrincipalSynchronizationJob -ServicePrincipalId $ServicePrincipalId -SynchronizationJobId $JobId
    

Étape 13 : Superviser l’approvisionnement

Icône du locataire source.
Locataire source

  1. Maintenant que le travail d’approvisionnement est en cours d’exécution, dans le locataire source, utilisez la commande Get-MgServicePrincipalSynchronizationJob pour superviser la progression du cycle d’approvisionnement actuel, ainsi que les statistiques à ce jour, notamment le nombre d’utilisateurs et de groupes qui ont été créés dans le système cible.

    Get-MgServicePrincipalSynchronizationJob -ServicePrincipalId $ServicePrincipalId -SynchronizationJobId $JobId | Format-List
    
    Id                         : <JobId>
    Schedule                   : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSynchronizationSchedule
    Schema                     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSynchronizationSchema
    Status                     : Microsoft.Graph.PowerShell.Models.MicrosoftGraphSynchronizationStatus
    SynchronizationJobSettings : {AzureIngestionAttributeOptimization, LookaheadQueryEnabled}
    TemplateId                 : Azure2Azure
    AdditionalProperties       : {[@odata.context, https://graph.microsoft.com/v1.0/$metadata#servicePrincipals('<ServicePrincipalId>')/synchro
                                 nization/jobs/$entity]}
    
  2. En plus de superviser l’état du travail d’approvisionnement, utilisez la commande Get-MgAuditLogProvisioning pour récupérer les journaux d’approvisionnement et obtenir tous les événements d’approvisionnement qui se produisent. Par exemple, interrogez un utilisateur particulier et déterminez s’il a été correctement approvisionné.

    Get-MgAuditLogDirectoryAudit | Select -First 10 | Format-List
    
    ActivityDateTime     : 7/31/2023 12:08:17 AM
    ActivityDisplayName  : Export
    AdditionalDetails    : {Details, ErrorCode, EventName, ipaddr...}
    Category             : ProvisioningManagement
    CorrelationId        : aaaa0000-bb11-2222-33cc-444444dddddd
    Id                   : Sync_aaaa0000-bb11-2222-33cc-444444dddddd_L5BFV_161778479
    InitiatedBy          : Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuditActivityInitiator1
    LoggedByService      : Account Provisioning
    OperationType        :
    Result               : success
    ResultReason         : User 'user2@fabrikam.com' was created in Azure Active Directory (target tenant)
    TargetResources      : {<ServicePrincipalId>, }
    AdditionalProperties : {}
    
    ActivityDateTime     : 7/31/2023 12:08:17 AM
    ActivityDisplayName  : Export
    AdditionalDetails    : {Details, ErrorCode, EventName, ipaddr...}
    Category             : ProvisioningManagement
    CorrelationId        : aaaa0000-bb11-2222-33cc-444444dddddd
    Id                   : Sync_aaaa0000-bb11-2222-33cc-444444dddddd_L5BFV_161778264
    InitiatedBy          : Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuditActivityInitiator1
    LoggedByService      : Account Provisioning
    OperationType        :
    Result               : success
    ResultReason         : User 'user2@fabrikam.com' was updated in Azure Active Directory (target tenant)
    TargetResources      : {<ServicePrincipalId>, }
    AdditionalProperties : {}
    
    ActivityDateTime     : 7/31/2023 12:08:14 AM
    ActivityDisplayName  : Synchronization rule action
    AdditionalDetails    : {Details, ErrorCode, EventName, ipaddr...}
    Category             : ProvisioningManagement
    CorrelationId        : aaaa0000-bb11-2222-33cc-444444dddddd
    Id                   : Sync_aaaa0000-bb11-2222-33cc-444444dddddd_L5BFV_161778395
    InitiatedBy          : Microsoft.Graph.PowerShell.Models.MicrosoftGraphAuditActivityInitiator1
    LoggedByService      : Account Provisioning
    OperationType        :
    Result               : success
    ResultReason         : User 'user2@fabrikam.com' will be created in Azure Active Directory (target tenant) (User is active and assigned
                           in Azure Active Directory, but no matching User was found in Azure Active Directory (target tenant))
    TargetResources      : {<ServicePrincipalId>, }
    AdditionalProperties : {}
    

Conseils de dépannage

Symptôme - Erreur de privilèges insuffisants

Lorsque vous essayez d’effectuer une action, vous recevez un message d’erreur semblable au suivant :

code: Authorization_RequestDenied
message: Insufficient privileges to complete the operation.

Cause

Soit l’utilisateur connecté ne dispose pas de privilèges suffisants, soit vous devez consentir à l’une des autorisations requises.

Solution

  1. Vérifiez que les rôles nécessaires vous sont attribués. Consultez Prérequis, précédemment dans cet article.

  2. Lorsque vous vous connectez avec Connect-MgGraph, veillez à spécifier les étendues requises. Consultez Étape 1 : se connecter au locataire cible et Étape 4 : se connecter au locataire source plus haut dans cet article.

Symptôme – erreur New-MgPolicyCrossTenantAccessPolicyPartner_Create

Lorsque vous essayez de créer une configuration de partenaire, vous recevez un message d’erreur semblable au suivant :

New-MgPolicyCrossTenantAccessPolicyPartner_Create: Another object with the same value for property tenantId already exists.

Cause

Vous essayez probablement de créer une configuration ou un objet qui existe déjà, éventuellement à partir d’une configuration précédente.

Solution

  1. Vérifiez votre syntaxe et que vous utilisez l’ID de locataire correct.

  2. Utilisez la commande Get-MgPolicyCrossTenantAccessPolicyPartner pour répertorier l’objet existant.

  3. Si vous disposez d’un objet, vous devrez peut-être effectuer une mise à jour à l’aide de Update-MgPolicyCrossTenantAccessPolicyPartner

Symptôme : erreur Request_MultipleObjectsWithSameKeyValue

Lorsque vous essayez d’activer la synchronisation utilisateur, vous recevez un message d’erreur semblable au suivant :

Invoke-MgGraphRequest: PUT https://graph.microsoft.com/v1.0/policies/crossTenantAccessPolicy/partners/<SourceTenantId>/identitySynchronization
HTTP/1.1 409 Conflict
...
{"error":{"code":"Request_MultipleObjectsWithSameKeyValue","message":"A conflicting object with one or more of the specified property values is present in the directory.","details":[{"code":"ConflictingObjects","message":"A conflicting object with one or more of the specified property values is present in the directory.", ... }}}

Cause

Vous essayez probablement de créer une stratégie qui existe déjà, éventuellement à partir d’une configuration précédente.

Solution

  1. Vérifiez votre syntaxe et que vous utilisez l’ID de locataire correct.

  2. Utilisez la commande Get-MgPolicyCrossTenantAccessPolicyPartnerIdentitySynchronization pour répertorier le paramètre IsSyncAllowed.

    (Get-MgPolicyCrossTenantAccessPolicyPartnerIdentitySynchronization -CrossTenantAccessPolicyConfigurationPartnerTenantId $SourceTenantId).UserSyncInbound
    
  3. Si vous avez une stratégie existante, vous devez peut-être effectuer une mise à jour avec la commande Set-MgPolicyCrossTenantAccessPolicyPartnerIdentitySynchronization pour activer la synchronisation des utilisateurs.

    $Params = @{
        userSyncInbound = @{
            isSyncAllowed = $true
        }
    }
    Set-MgPolicyCrossTenantAccessPolicyPartnerIdentitySynchronization -CrossTenantAccessPolicyConfigurationPartnerTenantId $SourceTenantId -BodyParameter $Params
    

Étapes suivantes