Wednesday 29 January 2020

Bulk DNS Record Deletion

# Update List of HOSTNAME in host.txt file

$DNSDATAs = Get-Content .\host.txt

foreach ($dns in $DNSDATAs){

# If DNS Record exist, If block will process

If ((Get-DnsServerResourceRecord -ZoneName lab.local $dns -ErrorAction SilentlyContinue).hostname -ne $null) {
    Remove-DnsServerResourceRecord -ZoneName lab.local -RRType "A" -Name $dns -Force
    $Result = "$dns Record deleted successfully"| Out-File -Append ".\dnslog.log"

# If DNS Record not found else block will process

} else {
    $Result = "$dns Record NOT found in Zone" | Out-File -Append ".\dnslog.log"
}
}

No comments:

Post a Comment