如何使用从DNS文件加载的powershell创建新的Microsoft DNS区域



我正在尝试使用Powershell在Microsoft DNS服务器上创建一些DNS区域。我们已经创建并完全填充了DNS文件。我们的想法是将这些DNS文件放在dns目录中,然后运行脚本导入它们。我遇到的问题是,当我运行下面的命令时,它会用一个新的(空的(区域/文件覆盖填充的DNS文件。

Add-DnsServerPrimaryZone -Name abc.com -ZoneFile "abc.com.dns"

请问我该怎么做?

如果您移动文件并使用创建DNS区域

Add-DnsServerPrimaryZone -Name abc.com -ZoneFile "abc.com.dns" 

然后你能用添加A记录吗

$entries = Import-Csv <filename with DNS Records>
foreach($entry in $entries){
Add-DnsServerResourceRecordA -Name $entry.name -ZoneName abc.com -IPv4Address $entry.ip -ComputerName $entry.HostName 
}

对于其他记录类型,还有一堆其他ADD命令,因此您可能能够构建一个脚本,根据内容从输入中识别类型

https://learn.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecorda?view=win10-ps

您可以使用dnscmd轻松实现这一点。

dnscmd /zoneadd test.com /primary /file test.com.dns /load

区域文件必须位于C:\Windows\System32\dns中。

据我所知,没有专门的Powershell模块用于导入DNS区域。您可以使用Get-Command -Module DnsServer -Noun *Zone*进行验证。

最新更新