Question

I am trying to create Subnets in existing Sites loaded in from a .txt file. My code looks like this:

 <#Add subnets to matching sites#>
        $i=0
        foreach($_ in $subnetList){
            $currentSites = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites
            if($currentSites.Subnets -match $_){
                continue
            }else{                            
                New-ADReplicationSubnet -Name $_ -Site $siteList[$i]
                $i++
            }
        }

The $subnetList and the $siteList have the following content:

$subnetList = 
    10.0.0.0/21
    10.0.5.0/21
    10.0.9.0/24
    10.0.11.0/24
    10.0.14.0/24
    10.0.19.0/24

<#SITENAME1 has 2 occurences.#>
$siteList = 
    SITENAME1
    SITENAME1
    SITENAME2
    SITENAME3
    SITENAME4
    SITENAME5

The problem I run into is that when SITENAME1 has the first subnet added it returns an error on the second attempt:

New-ADReplicationSubnet : An attempt was made to add an object to the directory 
with a name that is already in use

Is there any way to still add an extra subnet to this Site? Technet talks about the -Instance switch. I am not sure on how to implement that I'm afraid.

Was it helpful?

Solution

I have found a solution to this problem. It is indeed possible to add multiple subnets to a single site via PowerShell.

for ($i = 0; $i -lt $($c.Site).Count; $i++){ 
   $currentSites = Get-ADReplicationSite -Filter *
   $currentSubnets = Get-ADReplicationSubnet -Filter *                                                              
         New-ADReplicationSite -Name $c.Site[$i]
         New-ADReplicationSubnet -Name $c.Subnet[$i]
         Set-ADReplicationSubnet $c.Subnet[$i] -Site $c.Site[$i]                                     
}

The solution is to first create both the site and the subject and then assign the subnet to the site. This is not possible in the graphical interface. (In the GUI it is mandatory to assign a subnet to a site before exiting the interface)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top