Waiting for AD replication

Welcome Forums General PowerShell Q&A Waiting for AD replication

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
3 months ago.

  • Author
    Posts
  • #146355

    Participant
    Topics: 1
    Replies: 17
    Points: 36
    Rank: Member

    A general question for the community, I'm curious if anyone has any tips or suggestions on how they manage scripts that create/edit/remove objects in Active Directory that require waiting on AD replication.

    For example, say you have a script that creates a group, and then the next line sets some additional properties on that group or takes some action on the new group.  However powershell responds that the new group does not exist (because it has not replicated through AD yet).  Typically just building in a Sleep command for say 30 seconds after the group is created allows enough time that the new group is propagated to the other domain controllers, which after the 30 seconds you are able to add your properties to the group because it is now successfully found in AD.

    I hope I'm explaining this clearly.  This is just a hypothetical scenario but I was curious if anyone has any real-world experience in better managing this type of situation where you have to wait for an object to replicate in AD before continuing to work with it.  If you are just creating one new group waiting 30 seconds is not an issue, but this would add up if you had to create and then edit 1000 groups.  Would specifying a specific domain controller in your command allow for setting a shorter sleep period ?

    Again, just curious for feedback on how different people manage these situations.  Thanks !

  • #146379

    Participant
    Topics: 8
    Replies: 375
    Points: 445
    Helping Hand
    Rank: Contributor
    [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain().DomainControllers | foreach {
        $_.SyncReplicaFromAllServers($_.Partitions[0],'CrossSite')
    } 
    
  • #146382

    Participant
    Topics: 1
    Replies: 1374
    Points: 1,884
    Helping Hand
    Rank: Community Hero

    It will be hard to help you without seeing your actual code or at least the relevant part of it. Sometimes you can pass the resulting object along the pipeline with the parameter -PassThru. Or you save the "result" of a command in a variable and use this for further actions. And sometimes it will be enough wehn you simply specify the Domain Controller with the parameter -Server you like the command to run on.

The topic ‘Waiting for AD replication’ is closed to new replies.