如何使用 Powershell 从 DNS 中删除特定的 AAAA 记录?
How to remove specific AAAA records from DNS using Powershell?
我想从我们的 DNS 服务器中删除所有 public IPv6 地址,例如2000:a61:10e3:8f01:: 或 2003:d8:8bd7:c000:: 但保留所有 link-本地或站点本地地址,例如fd00:: 不变。
我想出了如何获取所有 AAAA 记录的列表:
$DNSServer = "dns.domain.net"
$ZoneName = "domain.net"
$NodeDNS = $null
$NodeDNS = Get-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -RRType AAAA -ErrorAction SilentlyContinue
现在的问题是如何在调用 Remove-DNSServerResourceRecord 命令之前过滤所有这些 "public" 记录?
Remove-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -InputObject $NodeDNS -Force
将删除所有 AAAA 记录。
您可以使用这个过滤器:
Get-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -RRType AAAA -ErrorAction SilentlyContinue |
Where-Object {$_.RecordData.IPv6Address.IPAddressToString -match '2000:a61:10e3:8f01' -or `
$_.RecordData.IPv6Address.IPAddressToString -match '2003:d8:8bd7:c000' -and `
$_.RecordData.IPv6Address.IPAddressToString -notmatch '^fd00'
} | Remove-DnsServerResourceRecord -ZoneName $ZoneName -WhatIf
该示例使用 Where-Object 来过滤具有特定字符串 -match
-and
和 -notmatch
的返回数据,有关详细说明,请参阅 Get-Help about_Comparison_Operators
我已经添加了 -WhatIf
参数,它在实际进行更改之前显示了它的作用,只是为了确保在删除之前获得正确的结果,如果没问题,请删除 -WhatIf
我想从我们的 DNS 服务器中删除所有 public IPv6 地址,例如2000:a61:10e3:8f01:: 或 2003:d8:8bd7:c000:: 但保留所有 link-本地或站点本地地址,例如fd00:: 不变。
我想出了如何获取所有 AAAA 记录的列表:
$DNSServer = "dns.domain.net"
$ZoneName = "domain.net"
$NodeDNS = $null
$NodeDNS = Get-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -RRType AAAA -ErrorAction SilentlyContinue
现在的问题是如何在调用 Remove-DNSServerResourceRecord 命令之前过滤所有这些 "public" 记录?
Remove-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -InputObject $NodeDNS -Force
将删除所有 AAAA 记录。
您可以使用这个过滤器:
Get-DnsServerResourceRecord -ZoneName $ZoneName -ComputerName $DNSServer -RRType AAAA -ErrorAction SilentlyContinue |
Where-Object {$_.RecordData.IPv6Address.IPAddressToString -match '2000:a61:10e3:8f01' -or `
$_.RecordData.IPv6Address.IPAddressToString -match '2003:d8:8bd7:c000' -and `
$_.RecordData.IPv6Address.IPAddressToString -notmatch '^fd00'
} | Remove-DnsServerResourceRecord -ZoneName $ZoneName -WhatIf
该示例使用 Where-Object 来过滤具有特定字符串 -match
-and
和 -notmatch
的返回数据,有关详细说明,请参阅 Get-Help about_Comparison_Operators
我已经添加了 -WhatIf
参数,它在实际进行更改之前显示了它的作用,只是为了确保在删除之前获得正确的结果,如果没问题,请删除 -WhatIf