Active Directory Replication Cmdlets – Site Creation


To create an Active Directory site with VBScript took about 30 lines of code and it took a few less lines to create an Active Directory site with v1 of PowerShell. With the introduction of the Active Directory PowerShell module in Windows Server 2008 R2, you could cut this down to 5 lines.

Here's an example:

#Previously on 'PowerShell is Ace'…

New-ADObject -Name "Iceland" -Type Site -Path "CN=Sites,CN=Configuration,DC=fabrikam,DC=com"

 

New-ADObject -Name "NTDS Site Settings" -Type NTDSSiteSettings -Path "CN=Iceland,CN=Sites,CN=Configuration,DC=fabrikam,DC=com"

 

New-ADObject -Name "Servers" -Type serversContainer -Path "CN=Iceland,CN=Sites,CN=Configuration,DC=fabrikam,DC=com"

 

New-ADObject -Name "10.150.15.0/24" -Type Subnet -Path "CN=Subnets,CN=Sites,CN=Configuration,DC=fabrikam,DC=com" `

-OtherAttributes @{siteObject="CN=Iceland,CN=Sites,CN=Configuration,DC=fabrikam,DC=com"; location='Iceland/Reykjavik'}

 

New-ADObject -Name 'England-Iceland' -Type SiteLink -Path "CN=IP,CN=Inter-Site Transports,CN=Sites,CN=Configuration,DC=fabrikam,DC=com" `

-OtherAttributes @{siteList="CN=England,CN=Sites,CN=Configuration,DC=fabrikam,DC=com","CN=Iceland,CN=Sites,CN=Configuration,DC=fabrikam,DC=com"; replInterval=15; cost=50}

 

Notice that everything's driven by New-ADObject. We have to create the site object, the NTDS Site Settings object, the Servers container object, the subnet object and the site link object. Still, 5 lines is much better than 30!

The AD Replication cmdlets, introduced in Windows Server 2012, give us New-ADReplicationSite, New-ADReplicationSubnet, New-ADReplicationSiteLink, Set-ADReplicationSiteLink.

Let's see them in action:

#In PS v3… let's create a new site

New-ADReplicationSite -Name Brazil

 

New-ADReplicationSubnet -Name "10.200.20.0/24" -Site 'Brazil' -Location 'Brazil/Rio'

New-ADReplicationSiteLink -Name 'England-Brazil' -SitesIncluded England,Brazil

 

Set-ADReplicationSiteLink England-Brazil -Cost 50 -ReplicationFrequencyInMinutes 15

 

Four short lines gives us a fully functioning site! Let's use PowerShell to look at out newly created site and subnet with the aid of Get-ADreplicationSite.

Get-ADReplicationSite -Identity 'Brazil' -Properties Subnets | Format-Table Name,Subnets -AutoSize -Wrap

  

 

Now, let's look at the new site link with Get-ADreplicationSiteLink.

Get-ADReplicationSiteLink -Identity 'England-Brazil' | Format-Table Name,Cost,ReplicationFrequencyInMinutes,SitesIncluded -AutoSize -Wrap

 

  

PowerShell: helping administrators be awesome since 2006.

 

Comments (3)

  1. Anonymous says:

    thanks

  2. Anonymous says:

    Pingback from Active Directory Replication Cmdlets – Site Creation | MS Tech BLOG

  3. WO!K says:

    Very helpful to a common task in the shell. This is the only site where I got a straight answer.