powershell - 如何以编程方式更新 DNS 记录

标签 powershell windows-7 dns windows-server-2008-r2

我正在尝试更新位于(我相信)服务器上以下路径的 DNS 记录:

ServerName -> Forward Lookup Zones -> domain.com -> test

其中 DNS 记录称为 test,类型为 Host(A)

我从 here 下载了 DNSShell 模块并尝试使用以下命令更改 DNS 记录(包含 IP 地址)的“数据”列:

Set-DNSRecord -Identity "test.domain.com"

但是我得到了这个错误:

Cannot validate argument on parameter 'Identity'. The argument "test.domain.com" does not match the "^\\.\root\MicrosoftDNS:MicrosoftDNS_" pattern. Supply an argument that matches "^\\.\root\MicrosoftDNS:MicrosoftDNS_" and try the command again.

所以我更新了 Identity 参数如下:

Set-DNSRecord -Identity "\\Servername\root\MicrosoftDNS:MicrosoftDNS_"

但现在我看到了:

Set-DNSRecord : Specified argument was out of the range of the valid values. Parameter name: Path

当我尝试添加 -Path 时,它说没有这样的参数!有谁知道我需要在哪里添加 DNS 的 test.domain.com 部分来告诉命令要更新哪条记录?该模块的这一部分的文档不完整,我似乎找不到任何替代方案。

我可以调用 Get-DNSRecord 并查看我需要更新的记录,但是任何 Set 的尝试都会被阻止,因为我不知道这些路径是如何构建的。

非常感谢任何帮助。

最佳答案

您也可以为 Microsoft 的 DNS 服务器使用默认的 PowerShell 模块,示例如下所示:

Add-DnsServerResourceRecordA -Name "recordname" -IPv4Address "192.168.0.0" -ZoneName "domain.com" -AllowUpdateAny -AgeRecord 

如果您需要在此之前删除,像这样的东西应该可以工作:

Remove-DnsServerResourceRecord -ZoneName "domain.com" -Name "recordname" -RRType "A" -Force

关于powershell - 如何以编程方式更新 DNS 记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36768539/

相关文章:

iis - 子域名指向同一IIS中的不同网站

powershell - 通过 Powershell 远程获取 WinEvent

python - Win7 上的 Tkinter highlightcolor 选项

python - 非阻塞主机名解析?

compiler-construction - 如何在 Eclipse 和 Windows 中指向我的编译器和链接器?

c# - 如果使用 C# 运行,如何关闭 Windows 屏幕保护程序?

dns - pods 中的SkyDNS MissingClusterDNS

java - 如何执行包含双引号的 PowerShell 命令

powershell - 相当于 PowerShell 中的 *nix 折叠

powershell - 解释奇怪的函数调用处理/结果