【问题标题】:How do you create a new Microsoft DNS zone with powershell that loads from a DNS file?如何使用从 DNS 文件加载的 powershell 创建新的 Microsoft DNS 区域?
【发布时间】:2021-01-12 22:58:40
【问题描述】:

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

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

请问我该怎么做?

【问题讨论】:

  • "...it overwrites the populated DNS file with a new (empty) zone/file." --- 因为这就是 cmdlet 的用途。根据帮助文件定义[The Add-DnsServerPrimaryZone cmdlet adds a specified primary zone on a Domain Name System (DNS) server.],添加,而不是更新或附加。永远不要在未经验证的情况下运行破坏性代码(添加、删除/删除、更新/修改等)。利用[-WhatIf / -Confirm]。要查看发生了什么,请使用 Trace-Command cmdlet。

标签: powershell dns


【解决方案1】:

如果您移动文件并使用创建 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://docs.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecorda?view=win10-ps

【讨论】:

    【解决方案2】:

    您可以使用dnscmd 轻松完成。

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-21
      • 1970-01-01
      • 2013-12-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多