Created
June 5, 2017 14:21
-
-
Save BrandonStiff/99e801b4dcbbedba6f2475657387e068 to your computer and use it in GitHub Desktop.
Invoke AD Replication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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