-
Notifications
You must be signed in to change notification settings - Fork 3
/
remove_dns.ps1
24 lines (21 loc) · 1.07 KB
/
remove_dns.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<#
.SYNOPSIS
This script will query all the zones on a DNS server then remove entries based on a criteria in this case IP
Addresses
.EXAMPLE
remove_dns.ps1
#>
foreach ($domainname in (Get-DnsServerZone -ComputerName crpnycdcrt01 | ? { ($_.IsReverseLookupzone -like "false") -and ($_.ZoneType -like "Primary") } | Select-Object -ExpandProperty ZoneName)) {
function list {
get-wmiobject -ComputerName dnsserver -Namespace root\microsoftDNS -Class MicrosoftDNS_ResourceRecord -Filter "domainname='$domainname'" |
Select-Object IPAddress, ownername |
Where-Object { ($_.IPAddress -match '10.7') -or ($_.IPAddress -match '10.9') -and ($_.IPAddress -notlike $null) } |
Sort-Object IPAddress
}
ForEach ($ip in list) {
$ipnew = $ip.ownername -replace "\..+"
#Remove-DnsServerResourceRecord -ZoneName "corporate.local" -RRType "A" -Name $($ip.ownername) -RecordData $($ip.IPAddress)
dnscmd crpnycdcrt01 /RecordDelete $domainname $ipnew A $ip.IPAddress /f
Write-output "$ipnew $($ip.IPAddress) has been removed from DNS"
}
}