Skip to content

Instantly share code, notes, and snippets.

@realslacker
Last active October 4, 2019 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save realslacker/880f0dd58b21015366dbd21ef0dc64c7 to your computer and use it in GitHub Desktop.
Save realslacker/880f0dd58b21015366dbd21ef0dc64c7 to your computer and use it in GitHub Desktop.
This function performs the configuration change described by the article "Active Directory Replication: Change Notification & You" by Chad Duffey (see: https://blogs.msdn.microsoft.com/canberrapfe/2012/03/25/active-directory-replication-change-notification-you/)
#requires -Modules ActiveDirectory
<#
.SYNOPSIS
Enables Change Notification on IP AD Replication Site Links
.PARAMETER SiteLink
The DistinguishedName of the SiteLink to modify.
.PARAMETER Domain
The Domain to operate on. Defaults to the current user's domain.
.PARAMETER Credential
The credential to use when performing the operation, if needed.
.PARAMETER Force
Force the operation to be performed even if the script detects that change
notification is already enabled.
.EXAMPLE
Get-ADReplicationSiteLink -Filter * | Enable-ADReplicationChangeNotification.ps1 -Verbose
.NOTES
This function performs the configuration change described by the article
"Active Directory Replication: Change Notification & You" by Chad Duffey
https://blogs.msdn.microsoft.com/canberrapfe/2012/03/25/active-directory-replication-change-notification-you/
#>
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory, ValueFromPipeline, Position=1)]
[string[]]
$SiteLink,
[string]
$Domain = $env:USERDOMAIN,
[pscredential]
$Credential,
[switch]
$Force
)
begin {
$CredentialSplat = @{}
if ( $Credential ) { $CredentialSplat.Credential = $Credential }
$ADDomainController = Get-ADDomainController -DomainName $Domain -Discover -Service ADWS
}
process {
foreach ( $SiteLinkItem in $SiteLink ) {
$ADReplicationSiteLinkItem = Get-ADReplicationSiteLink $SiteLinkItem -Properties options -Server $ADDomainController.HostName[0] -ErrorAction Stop
Write-Verbose ( 'Found AD site link {0} with options value {1}' -f $ADReplicationSiteLinkItem.Name, [int]$ADReplicationSiteLinkItem.options )
if ( -not $Force -and [int]$ADReplicationSiteLinkItem.options -band 1 ) {
Write-Warning ( 'Change Notification Already Enabled for {0}' -f $ADReplicationSiteLinkItem.Name )
continue
}
[int]$NewOptions = $ADReplicationSiteLinkItem.options -bor 1
if ( $PSCmdlet.ShouldProcess($ADReplicationSiteLinkItem.DistinguishedName, 'enable change notification') ) {
Set-ADReplicationSiteLink -Identity $ADReplicationSiteLinkItem.DistinguishedName -Replace @{options=$NewOptions} -Server $ADDomainController.HostName[0] @CredentialSplat
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment