如何使用从 DNS 文件加载的 powershell 创建新的 Microsoft DNS 区域?
How do you create a new Microsoft DNS zone with powershell that loads from a DNS file?
我正在尝试使用 Powershell 在 Microsoft DNS 服务器上创建一些 DNS 区域。我们已经创建并完全填充了 DNS 文件。我们的想法是,我们将这些 DNS 文件放在 \dns
目录中,然后 运行 脚本来导入它们。我遇到的问题是,当我 运行 下面的命令时,它会用新的(空的)zone/file.
覆盖填充的 DNS 文件
Add-DnsServerPrimaryZone -Name abc.com -ZoneFile "abc.com.dns"
请问我该怎么做?
您可以使用 dnscmd
轻松完成。
dnscmd /zoneadd test.com /primary /file test.com.dns /load
区域文件必须在 C:\Windows\System32\dns.
据我所知,没有用于导入 DNS 区域的特定 Powershell 模块。您可以使用 Get-Command -Module DnsServer -Noun *Zone*
.
进行验证
如果您移动文件并使用
创建 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 命令,因此您也许可以构建一个脚本来根据内容从输入中识别类型
我正在尝试使用 Powershell 在 Microsoft DNS 服务器上创建一些 DNS 区域。我们已经创建并完全填充了 DNS 文件。我们的想法是,我们将这些 DNS 文件放在 \dns
目录中,然后 运行 脚本来导入它们。我遇到的问题是,当我 运行 下面的命令时,它会用新的(空的)zone/file.
Add-DnsServerPrimaryZone -Name abc.com -ZoneFile "abc.com.dns"
请问我该怎么做?
您可以使用 dnscmd
轻松完成。
dnscmd /zoneadd test.com /primary /file test.com.dns /load
区域文件必须在 C:\Windows\System32\dns.
据我所知,没有用于导入 DNS 区域的特定 Powershell 模块。您可以使用 Get-Command -Module DnsServer -Noun *Zone*
.
如果您移动文件并使用
创建 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 命令,因此您也许可以构建一个脚本来根据内容从输入中识别类型