Friday, May 30, 2014

Scripting Replication of All Domain Controllers in a Site

I have been looking for a way to replicate all servers for a while but it seems that Microsoft doesn't want the KCC to function this way.  Repadmin seems to replicate (with /syncall) to only its configured replication partners.  Now if you use the /e it will replicate (to the best of my understanding) to domain controllers in other sites if they are configured as a partner.  So I found a way to do this using two commands, dsquery.exe and for.exe.  Dsquery is a powerful Microsoft tool that's been around for a while and allows for all sorts of functionality in the area of "Directory Services".  As a side note you can pipe in other "DS" commands such as dsadd, dsmod, dsmove, dsrm based on the former part of the query.
Anyway, just plug this script into a batch file, replacing SITENAME with the AD site you wish to replicate in and change the path to wherever you run your scripts from.

----------script begin --------------
dsquery server -o rdn -site "SITENAME" >C:\scripts\SITENAMEDCs.txt
For /F "delims=" %%i in (SITENAMEDCs.txt) do repadmin /syncall  %%~i
--------script end-------------------
The dsquery command will output the servers in the site one per line, surrounded in quotes.   The second line looks at each line in the file and runs the repadmin /syncall command.   The ~ in the latter part of the "for" line is used to parse the quotes that dsquery outputs in. Enjoy!


2 comments:

  1. Another helpful piece of PowerShell if you manage a lot of domain controllers, create an object and need it replicated quickly:

    Get-ADDomainController -filter * | ForEach {Sync-ADObject -object "CN=OBJECTNAME,OU=SOMEOU,DC=DOMAIN,DC=SUFFIX" -source DCyouCreatedOn.Domain.Suffix -destination $_.hostname}

    ReplyDelete
  2. Another helpful piece of PowerShell if you manage a lot of domain controllers, create an object and need it replicated quickly:

    Get-ADDomainController -filter * | ForEach {Sync-ADObject -object "CN=OBJECTNAME,OU=SOMEOU,DC=DOMAIN,DC=SUFFIX" -source DCyouCreatedOn.Domain.Suffix -destination $_.hostname}

    ReplyDelete