pscapng
pscapng

Reputation: 106

Is there a powershell replacement for Repadmin /syncall

Currently we are using the command repadmin /syncall /e [our dn] and repadmin /syncall /eP [our dn] to force replication betwen domain controllers. I am wanting to use powershell to sync the domain controllers but everything I see online indicates that I would have to simply call repadmin from within powershell, which to me seems hokey and like duct taping something instead of doing it right. Is there any PURE powershell equivelant of repadmin /syncall?

Upvotes: 1

Views: 6080

Answers (3)

Collin Chaffin
Collin Chaffin

Reputation: 942

I wrote this pure powershell function/script back last year to do exactly this and it looks like maybe that's where the other posted PS snippet answer here came from (I'll take as compliment). The other post saying it is not possible is absolutely incorrect this ADSI call and my script does in fact force a full sync just like a Repadmin /syncall simply test it and you will see - I use it quite a bit. It also does debug output and proper error checking. Here's the link to the Pure Powershell script on the MSDN site:

http://bit.ly/SyncADDomain

and the github repo where I even have the pure powershell script packaged into a MSI installer for simple deployment as well:

https://github.com/CollinChaffin/SyncADDomain

If you find it helpful please mark as answer. Thanks!

Upvotes: 2

Bob M
Bob M

Reputation: 942

Give this script a try:

[CmdletBinding()]
Param([switch]$AllPartitions)

$myDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain();

ForEach ($dc in $myDomain.DomainControllers) {
    $dcName = $dc.Name;
    $partitions = @();
    if ($AllPartitions) {
        $partitions += $dc.Partitions;
    } else {
        $partitions += ([ADSI]"").distinguishedName;
    }
    ForEach ($part in $partitions) {
        Write-Host "$dcName - Syncing replicas from all servers for partition '$part'"
        $dc.SyncReplicaFromAllServers($part, 'CrossSite')
    }
}

Upvotes: 1

Tim Ferrill
Tim Ferrill

Reputation: 1674

AFIAK there's not a full replacement for repadmin. Sync-ADObject will let you replicate a single object, but won't let you do a full sync. Also, that cmdlet is Windows 8.1/Windows Server 2012 R2 only. I would expect more comprehensive AD replication support in Windows Server vNext.

Upvotes: 1

Related Questions