我正在尝试在从.txt文件加载的现有站点中创build子网。 我的代码如下所示:
<#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++ } }
$subnetList和$siteList有以下内容:
$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
我遇到的问题是,当SITENAME1添加第一个子网时,它会在第二次尝试时返回一个错误:
New-ADReplicationSubnet : An attempt was made to add an object to the directory with a name that is already in use
还有什么办法可以添加一个额外的子网到这个网站? Technet谈到了-Instance交换机。 我不确定如何执行,我很害怕。
编辑:我也问了这个完全相同的问题在StackOverflow无济于事。 鉴于这可能更多的是面向Active Directory的社区,我想在这里尝试我的运气。 如果这违反规则,我会删除我的问题。
首先,有两个单独的列表与相应的键 – >值对并不那么明亮,但让我们来处理它。
脚本的当前条件逻辑将永远不会检测到现有的子网。 $currentSites将永远是一个网站的集合,而不是一个单一的网站对象。 集合没有Subnets参数,并且语句总是返回false,因为一个总是$null ,一个总是一个string。
在每次迭代中检索整个站点列表既费时又不必要,我们尝试使用已有的数据
由于$siteList数组中的索引n总是对应于$siteList数组中的索引n ,所以让我们使用一个普通计数器$n的常规for循环:
for ($n = 0; $n -lt $subnetList.Count; $n++) { // Let's see if the subnet exists, and what site it's assigned to $existingSubnet = Get-ADReplicationSubnet $subnetList[$n] -Properties Site -ErrorAction SilentlyContinue if(-not($existingSubnet)) { // None exist already, go ahead New-ADReplicationSubnet $subnetList[$n] -Site $siteList[$n] } else { if(($existingSubnet.Site).ToString() -ne $siteList[$n]) { // It exists but not in the right site Set-ADReplicationSubnet $subnetList[$n] -Site $siteList[$n] } } }
尽pipe如此,请将两个文件合并为一个CSV文件。 那么你可以使用foreach所有你想要的:-)
分号分隔CSV示例(SitesNSubnets.csv):
Subnet;SiteName 10.0.0.0/21;SITENAME1 10.0.5.0/21;SITENAME1 10.0.9.0/24;SITENAME2 10.0.11.0/24;SITENAME3 10.0.14.0/24;SITENAME4 10.0.19.0/24;SITENAME5
然后使用Import-CSV导入它:
$data = Import-CSV -Path .\SitesNSubnets.csv -Delimiter ";" foreach ($entry in $data) { Write-Host "This is the subnet: " + $entry.Subnet + " and this is the corresponding site: " $entry.SiteName }
链接到站点对象的子网对象告诉Active Directory和成员服务器域成员服务器属于哪个站点。
您不能将重复的子网对象添加到Active Directory。
您不能将子网对象链接到多个站点。
您可以使用包含重叠地址空间的子网对象。
除非你的服务器使用某种forms的IT量子物理,我不知道,服务器同时属于“迈阿密”站点和“达拉斯”站点是没有意义的,是吗?
你可以做的是在较大的子网中定义更小的,更具体的子网,以将其分配给不同的站点。 例如,您可以将10.0.0.0/8子网分配给达拉斯,然后您可以将10.2.0.0/16分配给迈阿密。 活动目录将优先于更具体的子网。 如果要强制一个特定的主机对特定站点进行身份validation,则甚至可以将/ 32子网对象添加到Active Directory。
<#SITENAME1 has 2 occurences.#> $siteList = SITENAME1 SITENAME1
为什么?!?! 这是什么意思? 正如Zoredache所说,这是打破的。 你不能有两个同名的网站。
这里是我试图添加一个名为阿灵顿的网站,当我已经有一个名为阿灵顿的网站:

在这里,我定义了几个子网对象,都链接到同一站点,其中10.1.2.64/26子网和10.0.0.0/24networking适合10.0.0.0/8“超网:”
