Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Invoke AD Replication
function Invoke-AdReplicationSync()
{
<#
.SYNOPSIS
Invokes an immediate AD Replication.
.PARAMETER AdServer
Specifies the AD server to replicate to. This server pulls AD data from all of its partners.
.PARAMETER Partition
Specifies a specific AD partition to replicate. If not specified, all AD partitions are replicated.
.EXAMPLE
Invoke-AdReplicationSync -AdServer dc1.domain.com
# Causes dc1.domain.com to pull from all of its replication partners.
#>
[CmdletBinding(SupportsShouldProcess=$true)]
param
(
[string] $AdServer = $ENV:COMPUTERNAME,
[string] $Partition = ""
)
$session = New-PSSession -ComputerName $AdServer
try
{
if ( $PSCmdlet.ShouldProcess($AdServer, "Invoke AD replication") )
{
$sb = `
{
param
(
$partition
)
$params = `
@(
"/e",
"/d"
)
if ( $partition )
{
$params += $ENV:COMPUTERNAME
$params += "`"$partition`""
}
else
{
$params += "/A"
}
$out = repadmin /syncall $params
Write-Host ("repadmin /syncall $params")
if ( $LASTEXITCODE -ieq 0 )
{
$out
}
else
{
throw $out
}
}
$out = Invoke-Command -Session $session -ScriptBlock $sb -ArgumentList $Partition
$out
}
}
catch
{
throw $_
}
finally
{
$session | Remove-PSSession -WhatIf:$False
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.