所有,
在进行一次重大刷新时,我意识到从DNS正向和反向查找区域内的“名称服务器”选项卡中手动删除已停用的域控制器太麻烦了。 我想出了以下脚本来自动删除这些记录。 我希望这会在将来对其他人有所帮助。
您需要做的就是在第2行上修改FQDN(完全合格的域名)。
#FQDN of the domain controller that has been decommissioned or is offline
$oldDMCName = "DMC1.domain.org"
#Get the PDC Emulator
$PDCe = Get-ADDomainController -Discover -Service PrimaryDC
#Get all DNS zones on the PDCe
$DNSZones = Get-DnsServerZone -ComputerName $PDCe
#Iterate DNS zones and remove the stale domain controller record where applicable
ForEach($zone in $DNSZones)
{
$zone = $zone.zoneName
$getZoneInfo2 = (Get-DnsServerResourceRecord -ZoneName $zone -Name "@" -RRType NS -ComputerName $PDCe).recorddata.nameserver
If($getZoneInfo -like "*$oldDMCName*")
{
Try
{
Remove-DNSServerResourceRecord -ZoneName $zone –Name “@” –RRType NS –RecordData $oldDMCName -ComputerName $PDCe -Force
}
Catch
{
Write-Output "Error removing $oldDMCName from $zone"
}
}
Else
{
Write-Output "$oldDMCName does not exist in zone $zone"
}
}